<html>
<head>
<script type="text/javascript">
var c=0;
var t;
var timer_is_on=0;
function timedCount()
{
document.getElementById('txt').value=c;
if(c == 100) return;
c=c+1;
t=setTimeout("timedCount()",30);
}
function doTimer()
{
if (!timer_is_on)
{
timer_is_on=1;
timedCount();
}
}
</script>
</head>
<body onload="doTimer()">
<form>
<input type="button" value="Start count!">
<input type="text" id="txt">
</form>
<p>Click on the button above. The input field will count forever, starting at 0.</p>
</body>
</html>
我想改變JavaScript的DOM問題
<input type="text" id="txt">
到
<div type="text" id="txt">
它不工作。 我認爲這個問題是
document.getElementById('txt').value=c;
但我試過
document.getElementById('txt').innerHTML=c;
它仍然無法正常工作。 有人能告訴我爲什麼嗎? 乾杯!
這很奇怪,我試過喲你在http://jsfiddle.net/8fpht/的代碼,它的工作原理。什麼不工作?在哪個瀏覽器中?你可以在控制檯中看到javascript錯誤嗎? –