Fitting
2015-12-09 09:54
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>定时器</title>
<script type="text/javascript">
var attime;
function clock(){
var weeekday = ["星期日","星期一","星期二","星期三","星期四","星期五","星期六"]
var time=new Date();
attime=time.getHours()+":"time.getMintues()+":"time.getSeconds()+weekday[time.getDay()];
document.getElementById("clock").value = attime;
}
setInterval(clock,1000);
</script>
</head>
<body>
<form>
<input type="text" id="clock" size="100"style="background:#000;color:#00ff00;width:200px"; />
</form>
</body>
</html>
定义的时候写的weeekday 下面写的weekday
getMinutes不是getMintues = =
多用F12有奇效哦~
<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>定时器</title> <script type="text/javascript"> window.onload = function(){ var attime; function clock() { var weekday = ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"] var time = new Date(); attime = time.getHours() + ":"+time.getMinutes() + ":"+ time.getSeconds() +"---"+ weekday[time.getDay()]; document.getElementById("clock").value = attime; } setInterval(clock, 1000); } </script> </head> <body> <form> <input type="text" id="clock" size="100" style="color:#00ff00;width:200px" ; /> </form> </body> </html>
一些变量名,函数名写错了。还有就是这种东西要放在window.onload 里
<script type="text/javascript"> var attime; function clock(){ //为里多写了一个e var weekday = ["星期日","星期一","星期二","星期三","星期四","星期五","星期六"] var time=new Date(); //getMintues 应该是 getMinutes 字符串拼接两边都要有+ attime=time.getHours()+":"+time.getMinutes()+":"+time.getSeconds()+weekday[time.getDay()]; document.getElementById("clock").value = attime; } setInterval(clock,1000); </script>
看注释
JavaScript进阶篇
468191 学习 · 21891 问题
相似问题