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