zoukankan      html  css  js  c++  java
  • 6、倒计时10秒

    <!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>
  • 相关阅读:
    jQuery 重新温习 遗忘知识点
    正则表达式获取博客园随笔1
    用django创建一个简单的sns
    WCF小实例以及三种宿主
    iOS: imageIO完成渐进加载图片
    Excel 菜单系统
    分布式EventBus的Socket实现
    Jenkins安装plugin
    邮件系统存储设计问答
    在Windows上使用CodeLite+MinGW+Clang进行开发
  • 原文地址:https://www.cnblogs.com/huanghuali/p/8458311.html
Copyright © 2011-2022 走看看