jquery countdown timer


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="../js/jquery.min.js"></script>
 
    <style>
 
        .active{font-size:16px;color:#ffffff;
            background: #000000;padding:10px;}
    </style>
 
</head>
<body>
 
 
数字从1变化到10:<div id="box1">0</div>
 
自动添加类:<div id="box2">0000000</div>
 
3秒后自动添加类:<div id="box3">0000000</div>
 
<script>
 
    $(function () {
 
        fn1("#box1");
        fn2("#box2");// method performed         var NUM = 0;    function Fn1 (Selector) {    });
 
        // 3 seconds after the method is performed automaticallysetTimeout ( "fn2 ( '# box3

 


        timer=setInterval(function(){
            num++;
           // alert(num)
           // var text="<span>"+num+",</span>"
           // $(selector).append(text);    //节点添加
            $(selector).text(num);
            if(num==10){
                clearInterval(timer);   //定时器清除;
            }
        },1000);
    };
 
 
    function fn2(selector){
        $(selector).addClass("active");
    };
 
 
 
 
</script>

Guess you like

Origin www.cnblogs.com/0826sw/p/11915285.html