求JavaScript显示本地时间完整代码,并根据时间提示问候语
JavaScript显示本地时间代码
- 提问者网友:杀手的诗
- 2021-05-14 07:38
- 五星知识达人网友:一把行者刀
- 2021-05-14 08:35
帮楼主写了个简易时间代码
并且修改了你的错误代码,经运行可行
<HTML>
<HEAD>
<TITLE>使用if...else语句判断密码是否正确</TITLE>
<SCRIPT Language="javascript">
var age;
age=prompt("请输入密码:","");//多了等号
age=parseInt(age);//少了分号
if (age==111){
alert("密码正确,您可以进入该网站!");
}
else {
alert("密码不正确,您不能进入该网站!");
window.close();
}
function time(){
var a=new Date();
document.write(a.toLocaleString());
setTimeout("time()",1000);}
</SCRIPT>
</HEAD>
<BODY onload="time()">
简易时间代码
</BODY>
</HTML>
- 1楼网友:行雁书
- 2021-05-14 10:27
<html> <head> <title>JS--时间问候</title>
<script language="javascript">
function time(){ var nowtime=new Date(); var h=nowtime.getHours();
if (h>=0 && h<6){ alert("小样,零晨了,怎么还不睡觉?"); }else if(h>=6 && h<8){ alert("早上好!"); }else if(h>=8 && h<12){ alert("上午好!"); }else if(h>=12 && h<14){ alert("中午好!"); }else if(h>=14 && h<18){ alert("下午好!"); }else if(h>=18 && h<20){ alert("晚上好,今天过的怎么样啊?"); }else{ alert("晚上好,到睡觉时间了!"); }
}
</script>
</head> <body> <input type="button" value="时间问候" onclick="time()"> <!--函数的调用--> </body> </html>
- 2楼网友:思契十里
- 2021-05-14 10:01
<html xmlns=" http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>无标题文档</title> <style type="text/css"> <!-- .k { font-size: 22px; color: #000000; height: 40px; width: 500px; background-color: #FF66FF; } --> </style> <script> function disTime(){ var good; var now=new Date(); var nian=now.getYear(); var yue=now.getMonth()+1; var ri=now.getDate(); var shi=now.getHours(); var fen=now.getMinutes(); var miao=now.getSeconds(); var week=0; if(miao<10){ miao="0"+miao; } if(fen<10){ fen="0"+fen; } if(shi<10){ fen="0"+shi; } if(shi<12){ good="上午好"; } else if(shi>12&&shi<18) { good="下午好"; } switch(now.getDay()){ case 0: week="星期日"; break; case 1: week="星期一"; break; case 2: week="星期二"; break; case 3: week="星期三"; break; case 4: week="星期四"; break; case 5: week="星期五"; break; case 6: week="星期六"; break; } document.form1.textfield.value=good+" 今天是:"+nian+"年"+yue+"月"+ri+"日"+week+" "+shi+":"+fen+":"+miao; var n=setTimeout("disTime()",1000); } </script> </head>
<body onLoad="disTime()"> <form name="form1" method="post" action=""> <label> <input name="textfield" type="text" class="k" size="90" readonly="true"> </label> </form> </body> </html>
- 3楼网友:执傲
- 2021-05-14 09:47