<html> <head> <script type="text/javascript"> function showTime(){ var c=document.getElementById("text"); var nowTime=new Date(); c.innerHTML="time is "+nowTime.toLocaleTimeString(); } function startTime(){ setInterval("showTime()",50); }</script> </head> <body onload="startTime()"> <div id="text"></div> </body> </html> 這個程序運行良好,一個簡單的clock,正常運行。我現在做一個簡單的調整<html> <head> <script type="text/javascript"> function startTime(){ function showTime(){ var c=document.getElementById("text"); var nowTime=new Date(); c.innerHTML="time is "+nowTime.toLocaleTimeString(); } setInterval("showTime()",50); } </script> </head> <body onload="startTime()"> <div id="text"></div> </body> </html> 運行出現錯誤 ReferenceError: showTime is not defined為何會這樣?showTime這個函數明明在startTime這個函數的開頭部位,為何會找不到?請解釋一下整個函數運行的過程。
showTime函數為何不能內置
冉冉說
2018-09-04 16:42:05