首页 > 其他 > 详细

6、倒计时10秒

时间:2018-02-22 16:33:45      阅读:210      评论:0      收藏:0      [点我收藏+]
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
<div id="showtimes">加载中。。。</div>
<script type="text/javascript">
    //设定倒数秒数
    var t = 10;
    //显示倒数秒数
    function showTime(){
        t -= 1;
        document.getElementById(showtimes).innerHTML= t;
        if(t==0){
            location.href=http://www.baidu.com;
        }
        //每秒执行一次,showTime()
        setTimeout("showTime()",1000);
    }
    //执行showTime()
    showTime();
</script>

</body>
</html>

 

效果图:

技术分享图片

当倒计时到等于0的时候停止为0:

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
<div id="showtimes">加载中。。。</div>
<script type="text/javascript">
    //设定倒数秒数
    var t = 10;
    //显示倒数秒数
    function showTime(){
        t -= 1;
        document.getElementById(showtimes).innerHTML= t;
        //每秒执行一次,showTime()
        s=setTimeout("showTime()",1000);
        //若倒计时到等于0,就停止
        if(t==0){
            t = 0;
            clearTimeout(s);
        }
    }
    //执行showTime()
    showTime();
</script>

</body>
</html>

 

6、倒计时10秒

原文:https://www.cnblogs.com/huanghuali/p/8458311.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!