Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have a load of divs with the class testimonial and I want to use jquery to loop through them to check for each div if a specific condition is true.

(我有一个带有类testimonial的div的加载,我想使用jquery循环遍历它们以检查每个div,如果特定条件为真。)

If it is true, it should perform an action.

(如果是,它应该执行一个动作。)

Does anyone know how I would do this?

(有谁知道我会怎么做?)

  ask by geoffs3310 translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
302 views
Welcome To Ask or Share your Answers For Others

1 Answer

Use each: ' i ' is the postion in the array, obj is the DOM object that you are iterating (can be accessed through the jQuery wrapper $(this) as well).

(使用each:' i '是数组中的postion, obj是你正在迭代的DOM对象(也可以通过jQuery包装器$(this)访问)。)

$('.testimonial').each(function(i, obj) {
    //test
});

Check the api reference for more information.

(有关更多信息,请查看api参考 。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...