1、第1类:传统简洁方式
1.在需要定时的页面上写上
2.关闭/开启定时器
关闭:window.clearInterval(Window.dsqID);
开启:重新写上述代码
第2类:通用面向对象方式
1.js编写dingshi类
var dingshi = function(options) {
this.dsqId=null;
this.o
2、ption ={time :300000,callback : "this.defaultFN"};
this.option =jQuery.extend( this.option, options);
this.defaultFN = function(ob) {
alert("这个定时器默认执行的函数");
}
this.start=function(){
if(this.dsqId==null){
var fn = eval(this.option.callback);
var time=this.option.time;
var ob = this;
this.
3、dsqId=window.setInterval(function(){fn(ob)},time);
}
}
this.end=function(){
window.clearInterval(this.getDSQId());
this.initDSQ();
}
this.getDSQId=function(){
return this.dsqId;
}
this.initDSQ=function(){
this.dsqId = null;
}
return this;
}
2.在你要使用定时的页面放上:
3.关闭/开启定时器
关闭:window.cscDSQ.end();
开启:window.cscDSQ.start();
结尾:我是把定时器弄成了第二种方式,代码还是很好理解的,而且导入一次大家都可以通用,当然,原理只是封装了第一种方式。不知道有没有朋友有什么建议或者更好的做法,发邮件给我601409985@