時間更新問題
<!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 time=new Date();?????????
??? attime=document.write(time.getHours()+":"+time.getMinutes()+":"+time.getSeconds());
??? document.getElementById("clock").value = attime;
? }
? setInterval(clock,100)
</script>
</head>
<body>
<form>
<input type="text" id="clock" size="50"? />
</form>
</body>
</html>
為什么時間不能自動更新
2017-03-11
?attime=document.write(time.getHours()+":"+time.getMinutes()+":"+time.getSeconds());
??? document.getElementById("clock").value = attime;
attime只是作為一個中間變量 為了賦值給 id=clock 的text 文本框(<input type="text" id="clock" size="50"? />) 所以不用寫出document.write(。。。。。。。。。。。。) ??
個人見解
2017-03-10
我去試了試,感覺問題出在attime=document.write(time.getHours()+":"+time.getMinutes()+":"+time.getSeconds());這一句,把document.write刪了就好了。
至于問什么目前我也不是很懂。但是,應該和document.write的機制有關系。