如何在类中执行多个setTimeout jQuery?
我有一个名为.content
的类,这个内容有一个名为.data-time
的属性,我想隐藏它所有的元素.content
类有setTimeout()
函数,有人可以帮帮我吗?
HTML代码:
;
jQuery代码:
$(".content", this ).each(function(){ var time = $(this).attr("data-time"); setTimeout(function() { $(this).hide("slow"); }, time); });
请帮我这样做。
在你的setTimeout
函数中, this
是窗口。 试试这个:
$(".content" ).each(function(){ var $this = $(this); var time = $this.data("time"); setTimeout(function() { $this.hide("slow"); }, time); });
或者,您可以使用.delay()jquery函数。
$('.content').each(function(){ var time = $(this).attr("data-time") $(this).delay(time).hide("slow") });
这里的例子。