<html>
<head>
<script type="text/javascript">
var c=0;
var t;
var timer_is_on=0;
function timedCount()
{
document.getElementById('txt').value=c;
c=c+1;
t=setTimeout("timedCount()",30);
}
function doTimer()
{
if (!timer_is_on)
{
timer_is_on=1;
timedCount();
}
}
</script>
</head>
<body>
<form>
<input type="button" value="Start count!" onClick="doTimer()">
<input type="text" id="txt">
</form>
<p>Click on the button above. The input field will count forever, starting at 0.</p>
</body>
</html>
如何修改此代码以使其停止在100? 谢谢!
答案 0 :(得分:2)
if (c >= 100){
//do stuff
}else{
t=setTimeout("timedCount()",30);
}
答案 1 :(得分:0)
替换
t=setTimeout("timedCount()",30);
与
if(c < 100) {
t=setTimeout("timedCount()",30);
}
下次尝试自己做,这个很容易......
安托
答案 2 :(得分:0)
只需在函数TimedCount
的顶部添加此行function TimedCount ()
{
if (c>100) return;
// use your existing code below
}