點(diǎn)擊提交只出現(xiàn)了一個(gè)輸入框
<!DOCTYPE?HTML> <html> <head> <meta?http-equiv="Content-Type"?content="text/html;?charset=utf-8"> <title>定時(shí)器</title> <script?type="text/javascript"> ??var?attime; ??function?clock(){ ????var?time=new?Date();?????????? ????attime=time.getHours()+":"+time.getMinutes()+":"+time.getSeconds(); ????document.getElementById("clock").value?=?attime; ??} ??setInterval("clock",1000); </script> </head> <body> <form> <input?type="text"?id="clock"?size="50"??/> </form> </body> </html>
2016-11-01
給個(gè)建議,如果你事先已經(jīng)知道,就當(dāng)我廢話..
setInterval("clock()",1000);這叫做字符串寫法,內(nèi)部函數(shù)只能獲取全局作用域函數(shù);
setInterval(clock,1000);這叫函數(shù)寫法,內(nèi)部函數(shù)可以獲取全局作用域和局部作用域的函數(shù);
第一種寫法當(dāng)函數(shù)內(nèi)部有參數(shù)時(shí)使用,若沒有參數(shù),推薦第二種寫法,第一出錯(cuò)率小,第二意思清晰明了,因?yàn)橐话銇碚f函數(shù)帶括號(hào)都是自執(zhí)行函數(shù)
2016-10-31
找到了 ?setInterval()函數(shù)里面的clock函數(shù)沒有加括號(hào)