“太多的递归” jquery错误
尝试创建背景图像幻灯片并收到此错误...这是我试图实现的代码:
var $j = jQuery.noConflict();
$j( function(){
var bgArr = [ 'sample1.jpg','sample2.jpg','sample3.jpg' ];
function backgroundSlide(i) {
$j("#home_sub_banner").css("background-image", "url("+bgArr[i++]+")");
if (i == bgArr.length) i = 0;
var st = setTimeout(arguments.callee(i), 1000);
}
backgroundSlide(0)
});
Trying to create a background-image slideshow and am getting this error... This is the code I'm trying to implement:
var $j = jQuery.noConflict();
$j( function(){
var bgArr = [ 'sample1.jpg','sample2.jpg','sample3.jpg' ];
function backgroundSlide(i) {
$j("#home_sub_banner").css("background-image", "url("+bgArr[i++]+")");
if (i == bgArr.length) i = 0;
var st = setTimeout(arguments.callee(i), 1000);
}
backgroundSlide(0)
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当您编写
arguments.callee(i)
时,您正在调用arguments.callee
并将其结果(如果有)传递给setTimeout
。这导致无限递归。您需要传递
setTimeout
和稍后调用arguments.callee
的匿名函数,如下所示:When you write
arguments.callee(i)
, you are callingarguments.callee
and passing its result (if any) tosetTimeout
. This results in infinite recursion.You need pass
setTimeout
and anonymous function that callsarguments.callee
later, like this:这将创建对
backgroundSlide
的无限递归方法调用。为什么不使用 setInterval 尝试不同的实现呢?
像这样的东西:
PS:上面的代码未经测试,但你会明白它的要点。
This is creating an infinite recrusive method call to
backgroundSlide
.Why don't you try a different implementation using setInterval instead?
Something like this:
PS: Above Code not tested but you'll get the gist of it.