JS中setInterval、setTimeout不能传递带参数的函数的解决方法

setInterval 和 setTimeout 这两个函数比较好用,但会遇到比如说我隔个几秒后要执行的函数是带参数的,这种情况怎么办?可以用匿名函数包装处理

//不带参数的函数

function test(){}

setTimeout(test,1000)
//带参数的函数,用匿名函数包装(可以实现动态传参)

function onemodelanima(o, tobestatus,  time, easing, origin){
if(easing == null){
easing = "";
}
if(time <=19){
time=19;
}
time = time/1000+'s';
easing = "cubic-bezier("+easing+")"; if(origin != null){
o.css("transform-origin", origin);
}
o.css('-webkit-transition',time +' '+easing);
o.removeClass('onebeforeshow oneaftershow onebeshow').addClass(tobestatus);
} setTimeout(function(){onemodelanima(one,'onebeshow',anima_one_in_time,one_flash.easing,one_flash.origin);},1000)
上一篇:JS里设定延时:js中SetInterval与setTimeout用法


下一篇:Javascript回调函数中的this指向问题