gpt4 book ai didi

javascript - jQuery 延迟被忽略

转载 作者:行者123 更新时间:2023-11-28 20:00:51 26 4
gpt4 key购买 nike

我正在运行以下代码,但由于某种原因,无论我在哪里放置延迟,该行都会立即执行。

任何帮助将不胜感激。

$('#team_a_grid, #team_b_grid').on("click", "td.clickable", function(){
var dot_or_cross ='<span>Dot</span>'
$(this).delay(3000).removeClass().html(dot_or_cross);
});

最佳答案

使用.setTimeout()

$('#team_a_grid, #team_b_grid').on("click", "td.clickable", function () {
var dot_or_cross = '<span>Dot</span>'
var $this=$(this);
setTimeout(function () {
$this.removeClass().html(dot_or_cross);
}, 3000);
});

正如评论中指出的

The .delay() method is best for delaying between queued jQuery effects. Because it is limited—it doesn't, for example, offer a way to cancel the delay—.delay() is not a replacement for JavaScript's native setTimeout function, which may be more appropriate for certain use cases.

Doc reference

关于javascript - jQuery 延迟被忽略,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21682556/

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