js form settimeout

<html>
<head>
<meta charset="utf8">
<script type="text/javascript">
var c=2;
var t
function timedCount()
{
document.getElementById('txt').value=c
c=c-1
t=setTimeout("timedCount()",1000)
if (c==0) {

setTimeout("document.getElementById('txt').value=0",0);
clearTimeout(t);
document.getElementById("form").submit();


}
}

function stopCount()
{
c=0;
setTimeout("document.getElementById('txt').value=0",0);
clearTimeout(t);
}
</script>
</head>

<body>

<form id="form" action="php.php">
<input type="button" value="开始计时!" onClick="timedCount()">
<input type="text" id="txt">
<input type="button" value="停止计时!" onClick="stopCount()">
</form>

<p>请点击上面的“开始计时”按钮来启动计时器。输入框会一直进行计时,从 0 开始。点击“停止计时”按钮可以终止计时,并将计数重置为 0。</p>

</body>

</html>

posted on 2015-07-22 22:19  liuwenbohhh  阅读(232)  评论(0编辑  收藏  举报