当前位置主页 > jquery文档 > :only-of-type

:only-of-type | jQuery API

2014-12-14 

返回值:jQuery:only-of-type

V1.9概述

选择所有没有兄弟元素,且具有相同的元素名称的元素。

如果父元素有相同的元素名称的其他子元素,那么没有元素会被匹配。

参数

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

示例

改变每一个按钮的文字,并且加一个边框,这些按钮的父元素只有这个按钮子元素。

<div>
<button>Sibling!</button>
<button>Sibling!</button>
</div>

<div>
<button>Sibling!</button>
</div>
<div>
None
</div>

<div>
<button>Sibling!</button>
<span>Sibling!</span>
<span>Sibling!</span>

</div>
<div>
<button>Sibling!</button>
</div> $("button:only-of-type").text("Alone").css("border", "2px blue solid");
Previous:
上一篇::only-child
Next:
下一篇::input
返回顶部