如何选择下一个"n"元素从jQuery中的当前元素开始? [英] How do I select the next "n" elements starting from the current element in jQuery?

查看:91
本文介绍了如何选择下一个"n"元素从jQuery中的当前元素开始?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从当前元素开始选择下一个"n"个元素?我的意思是...

How do I select the next "n" elements starting from the current element? What I mean is...

 $(this).attr(...);

我想做"n"次.对于n = 4的示例:

I want to do this "n" times. For the example of n=4:

$(this).attr(...);
$(this).next().attr(...);
$(this).next().next().attr(...);
$(this).next().next().next().attr(...);

或者可以循环执行:

for (i = 0; i < n; i++) {
    $(this).next().attr(...);
}

我该怎么做?是否可以通过选择下一个"n"个元素或循环来实现此目的?

How can I do this? Is there a way I can do this by selecting the next "n" elements or in a loop?

推荐答案

这应该有效:

$(this).nextAll().slice(0,4).attr(…)

更新:

这也将起作用:

$(this).nextAll("*:lt(4)").attr(…)

这篇关于如何选择下一个"n"元素从jQuery中的当前元素开始?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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