<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> 這個(gè)程序運(yùn)行良好,一個(gè)簡(jiǎn)單的clock,正常運(yùn)行。我現(xiàn)在做一個(gè)簡(jiǎn)單的調(diào)整<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> 運(yùn)行出現(xiàn)錯(cuò)誤 ReferenceError: showTime is not defined為何會(huì)這樣?showTime這個(gè)函數(shù)明明在startTime這個(gè)函數(shù)的開頭部位,為何會(huì)找不到?請(qǐng)解釋一下整個(gè)函數(shù)運(yùn)行的過程。
showTime函數(shù)為何不能內(nèi)置
冉冉說
2018-09-04 16:42:05