全部展开 | 全部折叠 | 速查表

返回值:jQueryeq(index|-index)

概述

获取第N个元素

参数

indexIntegerV1.1.2

一个整数,指示元素基于0的位置,这个元素的位置是从0算起。

-indexIntegerV1.4

一个整数,指示元素的位置,从集合中的最后一个元素开始倒数。(1算起)

示例

参数index描述:

获取匹配的第二个元素

HTML 代码:
<p> This is just a test.</p> <p> So is this</p>
jQuery 代码:
$("p").eq(1)
结果:
[ <p> So is this</p> ]

参数-index描述:

获取匹配的第二个元素

HTML 代码:
<p> This is just a test.</p> <p> So is this</p>
jQuery 代码:
$("p").eq(-2)
结果:
[ <p> This is just a test.</p> ]