怎么使用JavaScript实现时间动态显示,而且搜索输入框是否为空值验证?
- 提问者网友:情歌越听越心酸
- 2021-07-28 21:18
- 五星知识达人网友:行路难
- 2021-07-28 21:25
var day;
var date;
var time_start=new Date();
var clock_start=time_start.getTime();
if (today.getDay()==0) day="日";
if (today.getDay()==1) day="一";
if (today.getDay()==2) day="二";
if (today.getDay()==3) day="三";
if (today.getDay()==4) day="四";
if (today.getDay()==5) day="五";
if (today.getDay()==6) day="六";
date=""+(today.getYear())+"年"+(today.getMonth()+1)+"月"+(today.getDate())+"日 星期";
document.write("<span style='font-size:9pt;text-align:center'>"+date);
document.write(day+"</span>");
- 1楼网友:春色三分
- 2021-07-28 22:52
<script language="javascript"> function showtime(){ var now=new Date(); var year=now.getFullYear(); var month=now.getMonth(); var date=now.getDate(); var day=now.getDay(); var hour=now.getHours() var minu=now.getMinutes() var sec=now.getSeconds() var week; month+=1; if(month<10)month="0"+month; if(date<10)date="0"+date; if(hour<10)hour="0"+hour; if(hour>12){ hour="下午"+(hour-12); }else{ hour="上午"+hour; } if(minu<10)minu="0"+minu; if(sec<10)sec="0"+sec; switch(day){ case 1: week="星期一"; break; case 2: week="星期二"; break; case 3: week="星期三"; break; case 4: week="星期四"; break; case 5: week="星期五"; break; case 6: week="星期六"; break; default: week="星期日"; break; } var time=""; document.getElementById("time").innerHTML=year+"年"+month+"月"+date+"日"+week+" "+hour+":"+minu+":"+sec;
setTimeout("showtime()",1000); }
function sou(){
var sou_x=document.getElementById("sou").value;
if(sou_x==""){ alert("空");
} </script> <body onload="showtime()"> <div id="time" name="time"></div>
<form>
<input type="text" id="sou" name="sou" />
</rorm> </body>
- 2楼网友:洒脱疯子
- 2021-07-28 22:43
<input type="text" id="a" value="">
js里:var b = document.getElementById('a');
if(b= =null&&b==" "){
alert("不能为空");
}
动态时间,我感觉没必要因为大多人直接看电脑右下的时间,不过你要就给你
<script language="JavaScript"> <!-- function Time(){ if (!document.layers&&!document.all) return var Timer=new Date() var hours=Timer.getHours() var minutes=Timer.getMinutes() var seconds=Timer.getSeconds() var noon="AM" if (hours>12){ noon="PM" hours=hours-12 } if (hours==0) hours=12 if (minutes<=9) minutes="0"+minutes if (seconds<=9) seconds="0"+seconds //change font size here to your desire myclock="<font size='4' face='Arial' color=blue>"+hours+":"+minutes+":" +seconds+" "+noon+"</b></font>" if (document.layers){ document.layers.position.document.write(myclock) document.layers.position.document.close() } else if (document.all) position.innerHTML=myclock setTimeout("Time()",1000) } //--> </script> <span id="position" style="position:absolute;left:441px;top:190px; width: 128px; height: 30px"> </span>