• js实现100秒倒计时和简易时钟


    <!DOCTYPE html>

    <html>

    <head>

    <meta charset="utf-8">

    <title>100s倒计时</title>

    <style>

    body,div{margin:0;padding:0;}

    body{color:#fff;font:16px/1.5 5fae8f6f96c59ed1;}

    #countdown{300px;text-align:center;background:#000;margin:10px auto;padding:20px 0;}

    input{border:0;283px;height:50px;cursor:pointer;margin-top:20px;background:url(
    ) no-repeat;}

    input.cancel{background-position:0 -50px;}

    span{color:#000;80px;line-height:2;background:#fbfbfb;border:2px solid #b4b4b4;margin:0 10px;padding:0 10px;}

        </style>

        <script>

        window.onload = function(){

        var oCount = document.getElementById('countdown'),

           oInput = oCount.getElementsByTagName('input')[0],

           aSpan = oCount.getElementsByTagName('span'),

           timer = null;

        oInput.addEventListener('click',function(){

        this.className == ''?(timer = setInterval(updateTime,1000)):clearInterval(timer);

        this.className = this.className === 'cancel'?'':'cancel';

        },false);

        function format(a){

        return a.toString().replace(/^(d)$/,'0$1');

        }

        function updateTime(){

        //console.log(aSpan[0].innerHTML);

        var remain = parseInt(aSpan[0].innerHTML.replace(/^0/,''))*60+parseInt(aSpan[1].innerHTML.replace(/^0/,''));

        if (remain <= 0) {

        clearInterval(timer);

        return;

        }

        remain--;

        aSpan[0].innerHTML = format(parseInt(remain/60));

        aSpan[1].innerHTML = format(remain%60);

        }

        }

        </script>

    </head>

    <body>

    <div id="countdown">

    <span>01</span>分钟<span>40</span>秒

    <input type="button" value="" />

    </div>

    </body>

    </html>

     欢迎加入618237474,找群主私聊,送海量学习资料免费送

  • 相关阅读:
    Java分享笔记:关于Java反射机制
    Java分享笔记:自定义枚举类 & 使用enum关键字定义枚举类
    Java分享笔记:RandomAccessFile流 & 在文件指定位置插入内容
    Spark-源码-SparkContext的初始化
    Spark-源码-Spark-StartAll Master Worler启动流程
    Spark-源码-Spark-Submit 任务提交
    Hadoop2学习路程-HDFS
    JavaSE 第二次学习随笔(五)
    JavaSE 第二次学习随笔(四)
    JavaSE 第二次学习随笔(三)
  • 原文地址:https://www.cnblogs.com/xsns/p/6681049.html
Copyright © 2020-2023  润新知