clearTimeout方法在IE上的兼容问题

时间:2023-03-09 06:30:56
clearTimeout方法在IE上的兼容问题

今天在修改公司项目的bug时发现一个问题,出错代码如下:

 clearTimeout();
setTimeout(function(){
// 具体业务逻辑
},100);

这段代码在chrome、firefox浏览器中不会报错,但在IE上会报“参数是必选的”这个错误信息,也就是clearTimeout这个方法必须要传一个参数,具体应修改为:

 var timer = null;

 clearTimeout(timer);
timer = setTimeout(function(){
_this.imgUrl='/api/login/defaultKaptcha';
},100);