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

返回值:jQuery:nth-last-of-type(n|even|odd|formula)

V1.9概述

选择的所有他们的父级元素的第n个子元素,计数从最后一个元素到第一个。

因为jQuery的实现:nth-是严格来自CSS规范,n值是“1-indexed”,也就是说,从1开始计数。 对于所有其他选择器表达式比如:eq() 或 :even ,jQuery遵循JavaScript的“0索引”的计数。因此,给定一个单一<ul>包含3个<li>,$('li:nth-last-of-type(1)')选择第3个,也就是最后一个<li>。

这个不寻常的用法,可进一步讨论中找到 W3C CSS specification.

参数

nV1.9

The index of each child to match.

Must be a number. The first element has the index number 1.

evenV1.9

Selects each even child element

oddV1.9

Selects each odd child element

formulaV1.9

Specifies which child element(s) to be selected with a formula (an + b). Example: p:nth-last-child(3n+2) selects each 3rd paragraph, starting at the last 2nd child

示例

在每个匹配的ul中查找倒数第二个li

<ul>
	<li>1</li>
	<li>2</li>
	<li>3</li>
	<li>4</li>
</ul>

$("ul li:nth-last-of-type(2)");