jquery定时执行

来源:互联网 发布:为知笔记倒闭 编辑:程序博客网 时间:2024/05/08 02:56

setTimeout 用于延时器,只执行一次.

setInterval:用于多次执行.

   function getnums() {    $.get("http://special.ku6.com/office2010/api/nums.php?" + Math.random(), function(data){     nums = '<img src="images/cnt/left.gif" width="62" height="27" />';     $.each(data, function(i) {      num = data.substr(i, 1);      nums += '<img src="images/cnt/'+num+'.gif" width="16" height="27" />';     });     nums +='<img src="images/cnt/right.gif" width="5" height="27" />';     $("#default_count").html(nums);    });   }   $(document).ready(function(){    setInterval(getnums, 10000);   });


取消定时器


var wait=setInterval(function(){                if(!$(".box").is(":animated")){                    clearInterval(wait);                    //执行code                    alert("动画都已经执行完!");                }            },200);