javascript count number
javascript count number
<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?谢谢!
if (c >= 100){
//do stuff
}else{
t=setTimeout("timedCount()",30);
}
Replace
t=setTimeout("timedCount()",30);
if(c < 100) {
t=setTimeout("timedCount()",30);
}
下次试着自己做,这个真的很简单…
安东尼
在函数TimedCount的顶部添加这一行
function TimedCount ()
{
if (c>100) return;
// use your existing code below
}
相关文章:
- 使用模式格式化Number类型输入中的值
- 正在使用count++进行准备
- Javascript:用while循环在给定的count参数中重复一个字符串
- 如何将解析云代码的query.count结果保存在变量中
- AngularJS {{ val | number:1 }} 不四舍五入到小数点后 1 位
- angular type=[number]指令来阻止粘贴
- javascript/angularjs 将 String 与 number for loop 连接起来
- 如何修改或类似@model.count的内容,根据单元格值计算行数
- Javascript在实现时似乎跳过了一行(如果count==1)
- a=1和a=new Number()之间的差异
- 为什么Angularjs验证don't与输入[type=“number”]一起工作
- Jasmine .calls.count and .calls.any throwing error
- Protractor-分配给element.all.locator.count的变量返回NaN why
- jQuery 字符串转义 onclick='deleteRow(item“+count+”)' 如何引用项目和计数
- Javascript Regex - 9-digit number
- input[max={{number}}] 发出非常奇怪的行为
- 是否可以抓取连接到字符串的 NUMBER?(Javascript)
- javascript number of images
- 确定字符串是Date还是Number
- javascript count number