如何在类中执行多个setTimeout jQuery?

Arr*_*tra 2 html javascript jquery html5

我有一个叫做的类.content,这个内容有一个叫做的属性.data-time,我想隐藏所有.content带有setTimeout()函数类的元素,有人可以帮帮我吗?

HTML代码:

<div class="content first" data-time="200"> </div>
<div class="content second" data-time="300"> </div>
<div class="content third" data-time="400"> </div>
<div class="content fourth" data-time="500"> </div>;
Run Code Online (Sandbox Code Playgroud)

jQuery代码:

    $(".content", this ).each(function(){
        var time = $(this).attr("data-time");
        setTimeout(function() {
            $(this).hide("slow");
        }, time);
    });
Run Code Online (Sandbox Code Playgroud)

请帮我这样做.

Jas*_*n P 5

在你的setTimeout功能中,this是窗口.试试这个:

http://jsfiddle.net/uXVAs/

$(".content" ).each(function(){
        var $this = $(this);
        var time = $this.data("time");
        setTimeout(function() {            
            $this.hide("slow");
        }, time);
    });
Run Code Online (Sandbox Code Playgroud)