jQuery循环使用相同类的元素我有一个div加载类testimonial,我想使用jquery循环它们来检查每个div,如果特定条件为真。如果是,它应该执行一个动作。有谁知道我会怎么做?
3 回答

慕田峪9158850
TA贡献1794条经验 获得超7个赞
使用each:' i
'是数组中的位置,obj
是您正在迭代的DOM对象(也可以通过jQuery包装器访问$(this)
)。
$('.testimonial').each(function(i, obj) { //test});
有关更多信息,请查看api参考。

UYOU
TA贡献1878条经验 获得超4个赞
试试这个...
$('.testimonial').each(function(){ //if statement here // use $(this) to reference the current div in the loop //you can try something like... if(condition){ } });
添加回答
举报
0/150
提交
取消