我有一个javascript秒表,我有启动和停止,但我想添加另一个按钮重置请帮我解决这个问题。我已经放置了下面的JavaScript。
<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()",1000);
}
function doTimer()
{
if (!timer_is_on)
{
timer_is_on=1;
timedCount();
}
}
function stopCount()
{
clearTimeout(t);
timer_is_on=0;
}
</script>
</head>
<body>
<form>
<input type="button" value="Start count!" onClick="doTimer()">
<input type="text" id="txt">
<input type="button" value="Stop count!" onClick="stopCount()">
</form>
</body>
</html>
答案 0 :(得分:1)
<强> HTML:强>
<input type="button" value="reset count!" onClick="resetCount()">
<强> JS:强>
function resetCount() {
document.getElementById('txt').value =0;
c =0;
}