<html>
<head>
<script src="http://code.jquery.com/jquery-1.5.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>

version added: 1.0jQuery(':gt(index)')
-
-
index
- Zero-based index.
Description: Select all elements at an index greater than index within the matched set.
index-related selectors
The index-related selector expressions (including this "greater than" selector) filter the set of elements that have matched the expressions that precede them. They narrow the set down based on the order of the elements within this matched set. For example, if elements are first selected with a class selector (.myclass) and four elements are returned, these elements are given indices 0 through 3 for the purposes of these selectors.
Note that since JavaScript arrays use 0-based indexing, these selectors reflect that fact. This is why $('.myclass:gt(1)') selects elements after the second element in the document with the class myclass, rather than after the first. In contrast, :nth-child(n) uses 1-based indexing to conform to the CSS specification.
本文详细介绍了 jQuery 中的 ':gt()' 选择器的使用方法,该选择器可以选取索引大于指定数值的所有元素。文章通过一个 HTML 表格的例子展示了如何应用此选择器来更改表格中特定单元格的样式。
1132

被折叠的 条评论
为什么被折叠?



