jQuery ID/类的第n个项目 [英] jQuery nth item of id/class
本文介绍了jQuery ID/类的第n个项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用id选择器:
$("#id")
是否有办法仅对页面上具有该ID的第n个元素执行此操作?即
Is there a way to do this to only the nth element with that ID on the page? i.e.
$("#id:n")
推荐答案
页面中只能有一个具有给定ID的元素.
There can be only ONE element with a given id in a page.
来自 HTML规范:
文档中不得有多个具有相同元素的元素 ID值.
There must not be multiple elements in a document that have the same id value.
现在假设您要在页面中获取具有给定类的第n个元素,则可以使用 eq :>
Now suppose you want to get the nth element with a given class in your page, you may use eq :
$('.myclass').eq(index)
这篇关于jQuery ID/类的第n个项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文