?將setTimeout(startCount,1000);改成setTimeout("startCount()",1000);實現(xiàn)不了正確運行????
為何在window.onload=function()里面
將setTimeout(startCount,1000);改成setTimeout("startCount()",1000);實現(xiàn)不了正確運行????
為何在window.onload=function()里面
將setTimeout(startCount,1000);改成setTimeout("startCount()",1000);實現(xiàn)不了正確運行????
2018-07-13
舉報
2018-07-19
小妹妹我來了,這個我也遇到過,是因為你把startCount()放在window.onload中,他是一個內(nèi)部函數(shù),你在外面訪問不了,你改成這樣就可以了。寫成startCount,是引用的代碼串,而不像是"startCount()"引用的是一個函數(shù)。
//? window.onload = function(){
? ? var num=0;
? ? function startCount(){
? ? document.getElementById('count').value=num;
? ? num=num+1;
? ? setTimeout(startCount,1000)
? }
// ? startCount();
// }
?
<input type="text" id="count">
<input type="button" value="start"? onclick="startCount()"/>
2018-07-13
setTimeout(startCount,1000);
和setTimeout("startCount()",1000);這都是setTimeout()正確的寫法格式