87,910
社区成员
发帖
与我相关
我的任务
分享
<input id=s type=text value="0">
<input type="button" id="start" onclick="startCount()" value="start" disabled/>
<input type="button" id="stop" onclick="stopCount()" value="stop"/>
<script>
var flag = true;
window.onload = function (){
window.setInterval("count()",1000);
};
function startCount(){
flag = true;
document.getElementById("start").disabled = true;
document.getElementById("stop").disabled = false;
}
function stopCount(){
flag = false;
document.getElementById("start").disabled = false;
document.getElementById("stop").disabled = true;
}
function count(){
if(flag){
document.getElementById("s").value = parseInt(document.getElementById("s").value)+1;
}
}
</script>
<script>
var tid;
function show(){
var n = parseInt(document.forms[0].pad.value);
document.forms[0].pad.value = n+1;
}
function doStart(){
document.forms[0].pad.value="0";
if(tid!=null){clearInterval(tid);tid=null;}
tid=setInterval("show()",1000);
}
function doEnd(){
if(tid!=null){clearInterval(tid);tid=null;}
}
</script>
<form>
秒数显示 <input type="text" name="pad" value="0"><br>
<input type="button" onclick="doStart();" value="开始计时">
<input type="button" onclick="doEnd();" value="结束计时">
</form>
<script type="text/javascript">
var tid;
function timer(){
var ret = document.getElementById('ret');
if (tid) {
clearInterval(tid);
tid = null;
} else {
tid = setInterval(function(){
ret.value = parseInt(ret.value) + 1;
}, 100);
}
}
</script>
<input id="ret" type="text" value="0" readonly="true" />
<input type="button" value="Start" onclick="timer()"/>
<input type="button" value="Stop" onclick="timer()"/>