• 多个定时器任务


    <!DOCTYPE html>
    <html lang="zh-CN">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta http-equiv="X-UA-Compatible" content="ie=edge">
        <title>Document</title>
    </head>
    <body>
        <ul>
            <li class="time0"></li>
            <li class="time1"></li>
            <li class="time2"></li>
        </ul>
        <script src="http://code.jquery.com/jquery-2.1.1.min.js"></script>
        <script>
            var data = [
                {
                    id: 1,
                    time: 20000
                },
                {
                    id: 2,
                    time: 15000
                },
                {
                    id: 3,
                    time: 40000
                }
            ]
            
            function cutTime(cutTotalTime, index){
                var timer = setInterval(function(){
                    if(cutTotalTime <= 0){
                        clearInterval(timer);
                    }else{
                        cutTotalTime--;
                        let h = parseInt(cutTotalTime/3600);
                        let m = parseInt(cutTotalTime%3600/60);
                        let s = parseInt(cutTotalTime%60);
                        console.log("时分秒:", h, m, s);
                        let timeText = `${h}时:${m}分:${s}秒`;
                        $(".time"+index).text(timeText);
                    }
                }, 1000)
            }
    
            for(let i = 0; i < data.length; i++){
                let timein = parseInt(data[i].time / 1000);
                cutTime(timein, i);
            }
        </script>
    </body>
    </html>
  • 相关阅读:
    Chrome开发者工具详解(1)
    Chrome开发者工具详解(2)
    Ubuntu ADSL拨号上网
    Bash中单引号和双引号的区别
    建立菜单
    波浪号和Hyphen扩展
    标准IO和重定向
    Bash变量扩展修改符
    mysql主键约束和唯一性约束
    Here文档
  • 原文地址:https://www.cnblogs.com/muou2125/p/10536615.html
Copyright © 2020-2023  润新知