我有一个div与类的证明,我想用jquery循环通过他们检查每个div如果一个特定的条件是真的负载。如果为真,它应该执行一个操作。
有人知道我会怎么做吗?
我有一个div与类的证明,我想用jquery循环通过他们检查每个div如果一个特定的条件是真的负载。如果为真,它应该执行一个操作。
有人知道我会怎么做吗?
当前回答
试试这个…
$('.testimonial').each(function(){
//if statement here
// use $(this) to reference the current div in the loop
//you can try something like...
if(condition){
}
});
其他回答
divs = $('.testimonial')
for(ind in divs){
div = divs[ind];
//do whatever you want
}
$('.testimonal').each(function(i,v){
if (condition) {
doSomething();
}
});
使用简单的for循环:
var testimonials= $('.testimonial');
for (var i = 0; i < testimonials.length; i++) {
// Using $() to re-wrap the element.
$(testimonials[i]).text('a');
}
更精确的:
$.each($('.testimonal'), function(index, value) {
console.log(index + ':' + value);
});
你可以这样做
$('.testimonial').each(function(index, obj){
//you can use this to access the current item
});