gpt4 book ai didi

javascript - setTimeout() 语法?

转载 作者:行者123 更新时间:2023-11-28 13:50:12 25 4
gpt4 key购买 nike

我无法让以下 setTimeouts 正常工作:

$('a').click(function(){
if( last ) {
if( ($(this).attr('id') == last.attr('id')) ) {
setTimeout( function(){
$(this).parent().parent().css('visibility','hidden');
},500);
setTimeout( function(){
last.parent().parent().css('visibility','hidden');
},500);
found++;
}
if (found == 3) {
alert('You won a sticker!');
window.location.href = "#play2";
location.reload(); //resets found to 0
} last = null;
}
else {
last = $(this)
}
});

setTimeout 内部的函数可以正常工作,因此这不是问题。我想知道我的语法是否有问题。不过我没发现有什么问题。

最佳答案

在第一个setTimeout this ===窗口中。您可能想要创建一个闭包

var that = this
setTimeout( function(){
$(that).parent().parent().css('visibility','hidden');
},500);

关于javascript - setTimeout() 语法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11387848/

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