复制代码 代码如下: BR>"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> auto play <BR> //数组的第一项为时长,其他项可自定义 <BR> data = [["3","a"],["2","b"],["3","c"],["2","d"],["1",""]]; <br><br> $(document).ready(function(){ <BR> //设置触发事件 <BR> autoPlay.run = function(obj,num){ <BR> back(obj,num); <BR> }; <BR> autoPlay(); <BR> }); <br><br> function back(obj,num){ <BR> $("#div_show").html(obj[num][1]); <BR> } <br><br> function autoPlay(){ <BR> //初始化计数参数 <BR> if(autoPlay.num ==undefined) <BR> autoPlay.num = 0; <BR> //初始化时间点 <BR> if(autoPlay.timepoint ==undefined) <BR> autoPlay.timepoint = new Date().getTime(); <BR> if(autoPlay.num<data.length){ <BR> //函数句柄,data 数组,autoPlay.num当前下标 <BR> autoPlay.run(data,autoPlay.num); <BR> //按照元素时间长度播放数组 <BR> if(new Date().getTime()>autoPlay.timepoint){ <BR> //判断是否为第一次执行 <BR> if(autoPlay.first==undefined) <BR> autoPlay.first = true; <BR> else <BR> autoPlay.num++; <BR> //设置下一次播放的时间点 <BR> autoPlay.timepoint += (data[autoPlay.num][0]*1000); <BR> } <BR> setTimeout("autoPlay()",500); <BR> } <BR> } <br><br> $.extend({autoPlay:function(){ <BR> var defaults = {inteval:500}; <BR> }}); <br><br> 定义播放时间,可以定义事件