如何做一个类中的多setTimeout jQuery? [英] How to do Multiple setTimeout jQuery in a Class?

查看:141
本文介绍了如何做一个类中的多setTimeout jQuery?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为 .content 的类,这个内容有一个名为 .data-time 的属性,我想使用 setTimeout()函数隐藏所有具有 .content 类的元素,任何人都可以帮助我?



HTML代码

 < div class =content firstdata-time =200> < / DIV> 
< div class =content seconddata-time =300> < / DIV>
< div class =content thirddata-time =400> < / DIV>
< div class =content fourthdata-time =500> < / DIV取代;

jQuery代码

  $(。content,this).each(function(){
var time = $(this).attr(data-time);
setTimeout(function(){
$(this).hide(slow);
},time);
});

请帮助我做到这一点。

setTimeout 函数中,这个是窗口。试试这个:



http://jsfiddle.net/uXVAs /

  $(。content).each(function(){
var $ this = $(this);
var time = $ this.data(time);
setTimeout(function(){
$ this.hide(slow);
},时间);
});


i have a class called .content , this content has an attribute called .data-time, i want to hide all element where it has .content class with setTimeout() function, anybody can help me?

HTML code :

<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>;

jQuery Code :

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

please help me to do this.

解决方案

In your setTimeout function, this is the window. Try this instead:

http://jsfiddle.net/uXVAs/

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

这篇关于如何做一个类中的多setTimeout jQuery?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆