倒计时

<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>倒计时小例子</title>
<style type="text/css">
*{
padding:0px;
margin:0px;

}
</style>
</head>
<body>
<div id="did">10</div>
</body>
<script type="text/javascript">
//获取div元素对象
did=document.getElmentById("did");
//获取文本值
//s=did.innerHTML;
//alert(s);
m=10;
function fun(){
//1.做--
m--;
//2.把--后的m值赋值给div的文本值
did.innerHTML=m;
if(m<=0){
alert("该吃饭了");
//清除定时器
clearInterval(mytime);
}
}
//定时器
mytime=setInterval(fun,1000);
</script>
</html>

posted on 2020-03-21 21:02  kevin_yang123  阅读(2)  评论(0编辑  收藏  举报