jQuery eq()循环 [英] jQuery eq() loop

查看:166
本文介绍了jQuery eq()循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您能帮我吗?

$(document).ready(function(){
     $("ul.fam:eq(0) li:eq(2)").addClass("redbold");    
});

在此代码中,是否有一种方法可以循环或递增-> $("ul.fam:eq(0)中的'0'值? 像使其变为0、1、2、3、4、5等...并例如在到达"3"时停止循环.

In this code, is there a way to loop or increment the '0' value in -> $("ul.fam:eq(0) ? Like making it 0,1,2,3,4,5 and so on... and stop the loop for example when it reaches '3'

谢谢.

推荐答案

您可以使用 :lt() (小于索引)选择器,如下所示:

You can use the :lt() (less than index) selector, like this:

$(document).ready(function(){
  $("ul.fam:lt(4) > li:nth-child(3)").addClass("redbold");    
});

您可以在此处进行测试.

这与选择:eq(0):eq(3)相同.另外还有一个 :gt() 选择器...您可以将两者或 .slice() 以获得范围.

This will be the same as selecting :eq(0) through :eq(3). There's also a :gt() selector for the other way around...you can combine both or .slice() to get a range.

这篇关于jQuery eq()循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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