gpt4 book ai didi

javascript - 如何将参数传递给队列,然后传递给setTimeout?...困惑

转载 作者:行者123 更新时间:2023-12-02 19:39:32 25 4
gpt4 key购买 nike

我有两个容器,每个容器都会触发一些函数,该函数必须传递对象引用。该函数有嵌套的队列和setTimeout,我需要通过它们传递一个对象引用,以在正确的对象上执行它。

这是我尝试过的:

 var pimg=parent.find('.prod_img'); // This is the object I actually need to pass;

pimg.children('img:last').queue((function(aaa){
return function() {
whatthe= (function (itema) {
return function() {
itema.children('img').each(function(){
alert(itema.attr('id'));
//alert used for debug.
$(this).stop(false,false).animate({opacity:0},400,function(){
});
});
}
})(aaa)
aaa.data('timeout',window.setTimeout("whatthe()", 400));
}
})(pimg)
);

现在发生的情况是,如果我在两个对象上快速触发此函数,它会警告相同的 ID,这表明它永远不会传递对象引用。

注意,pimg是实际的对象,然后在队列引用中调用aaa,然后在setTimeout引用中调用itema,但它们都应该指向同一个对象。

如有任何建议,我们将不胜感激。谢谢

最佳答案

你的代码很伤脑筋,我没有你的 HTML 来实际测试它,但如果我正确理解你的问题,这应该可以工作:

var pimg = parent.find('.prod_img'); // This is the object I actually need to pass;

pimg.children('img:last').queue((function(aaa){
return function() {
var whatthe = (function (itema) {
return function() {
itema.children('img').each(function(){
alert(itema.attr('id'));
//alert used for debug.
$(this).stop(false,false).animate({opacity:0},400, function(){});
});
}
})(aaa)
aaa.data('timeout',window.setTimeout(whatthe, 400));
}
})(pimg));

关于javascript - 如何将参数传递给队列,然后传递给setTimeout?...困惑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10567798/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com