js实现简单倒计时

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title></title>
</head>
<body>

<span id="timeout">0</span>秒后返回首页

<script type="text/javascript">
    var timestart = 30;
    var timestep = -1;
    var timeID;
    function timecount() {
        document.getElementById("timeout").innerHTML = timestart;
        timestart += timestep;
        if(timestart < 0){
            alert(12)
          timestart = 30;
          //倒计时为0时执行xxxx方法   
        }
        timeID=setTimeout("timecount()",1000);
    }
    timecount()
</script> 
</body>
</html>

 

posted on 2023-02-08 18:02  泽一年  阅读(104)  评论(0编辑  收藏  举报

导航