:gt() Selector

gt selector

version added: 1.0jQuery(':gt(index)')

描述: 选择所有大于给定索引值的元素

索引相关的选择

这种索引相关的选择器(包括这个“大于”选择器)过滤他们前面的匹配表达式的集合元素。他们缩小匹配元素的顺序范围。例如,如果第一个选择器使用类选择器( .myclass )进行匹配,四个元素返回,这些元素是给定索引是03

请注意,由于JavaScript数组使用基于0的索引 ,这些选择器也是如此。这就是为什么$('.myclass:gt(1)')选择器选择文档中第二个MyClass类的元素,而不是第一个。与此相反,:nth-child(n)基于1的索引的,以符合CSS规范。

Example:

Finds TD #5 and higher. Reminder: the indexing starts at 0.

<!DOCTYPE html>
<html>
<head>
  <script src="http://code.jquery.com/jquery-latest.min.js"></script>
</head>
<body>
  <table border="1">

    <tr><td>TD #0</td><td>TD #1</td><td>TD #2</td></tr>
    <tr><td>TD #3</td><td>TD #4</td><td>TD #5</td></tr>

    <tr><td>TD #6</td><td>TD #7</td><td>TD #8</td></tr>
  </table>
<script>$("td:gt(4)").css("text-decoration", "line-through");</script>

</body>
</html>

Demo:

jQuery 1.6 API 中文版Clove整理、修订