返回值:jQuery:nth-last-of-type(n|even|odd|formula)
V1.9概述
選擇的所有他們的父級元素的第n個子元素,計數(shù)從最后一個元素到第一個。
因為jQuery的實現(xiàn):nth-是嚴格來自CSS規(guī)范,n值是“1-indexed”,也就是說,從1開始計數(shù)。 對于所有其他選擇器表達式比如:eq()?或?:even?,jQuery遵循JavaScript的“0索引”的計數(shù)。因此,給定一個單一<ul>包含3個<li>,$('li:nth-last-of-type(1)')選擇第3個,也就是最后一個<li>。
這個不尋常的用法,可進一步討論中找到?W3C CSS specification.
參數(shù)
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中查找倒數(shù)第二個li
<ul> <li>1</li> <li>2</li> <li>3</li> <li>4</li> </ul> $("ul li:nth-last-of-type(2)");