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>
  • 相关阅读:
    TypeError: Cannot destructure property `compile` of 'undefined' or 'null'
    关于Django多变关联查询的orm操作
    面试概念题
    飞机大战项目开发
    scrapy爬取的数据异步存储至MySQL
    卷积神经网络数据识别
    深度学习之TensorFlow
    随机森林的使用
    kaggle平台的配置与使用
    机器学习
  • 原文地址:https://www.cnblogs.com/huanghuali/p/8458311.html
Copyright © 2011-2022 走看看