head
script
var c=0
var t
function timedCount()
{
c=c+1
t=setTimeout("timedCount()",1000)
}
document.getElementById('txt').value=c
function stopCount()
{
clearTimeout(t)
}
/script
/head
body
form
input type="button" value="开始计时!" onClick="timedCount()"
input type="text" id="txt"
input type="button" value="停止计时!" onClick="stopCount()"
/form
p
请点击上面的“开始计时”按钮。输入框会从 0 开始一直进行计时。点击“停止计时”可停止计时。
/p
/body
我想问为什么运行上面代码时控制台会报错,但是如果把script部分移到移到body下面,代码就不会报错,为什么会这样的
代码没有加<>是因为好像加了<>这个论坛会自动执行我问题的代码