87,990
社区成员
发帖
与我相关
我的任务
分享<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
<div id="t" style="width:200px;height:50px;border:1px solid #333; font-size:20px; font-weight:bold; text-align:center"></div>
<div id="b" style="width:100px;height:20px; background:#ccc; cursor:pointer">点击倒计时</div>
<script type="text/javascript">
var t = document.getElementById("t");
var b = document.getElementById("b");
var count = 10;
var timer ;
function operator()
{
t.innerHTML ="倒计时:"+ count + "秒";
count --
if(count< 0) end();
}
function start()
{
timer = window.setInterval(operator,1000)
b.onclick = null;
}
function end()
{
window.clearInterval(timer);
count = 10
b.onclick=start;
}
b.onclick = start;
</script>
</body>
</html>
var t = document.getElementById("t");
var b = document.getElementById("b");
var count = 10;
var timer ;
function operator()
{
t.innerHTML ="倒计时:"+ count + "秒";
count --
if(count< 0) end();
}
function start()
{
timer = window.setInterval(operator,1000)
b.onclick = null;
}
function end()
{
window.clearInterval(timer);
count = 10
b.onclick=start;
}
b.onclick = start;