jQuery1.2選擇器
jQuery1.2選擇器
以下的文檔根據官網1.2選擇器漢化,并做相應的調整及加入了部份示例。
由于實際使用中選擇器在IE和非IE下會有不同的效果,請參照紅色的字樣。如有錯誤請及時聯系我。
緋雨漢化:http://feiyu.asgard.cn
基本選擇器
#myid |
返回: 對象> |
匹配一個id為myid的元素。 |
|
element |
返回: 對象> 數組 |
匹配所有的element元素 |
|
.myclass |
返回: 對象> 數組 |
匹配所有class為myclass的元素 |
|
* |
返回: 對象> 數組 |
匹配所有元素。該選擇器會選擇文檔中所有的元素,包括html,head,body |
|
selector1,selector2,selectorN |
返回: 對象> 數組 |
匹配所有滿足selector1或selector2或selectorN的元素 |
層次選擇
elementParent elementChild |
返回: 對象> 數組 |
匹配elementParent下的所有子元素elementChild。例如:$("div p") 選擇所有div下的p元素 |
|
elementParent > elementChild |
返回: 對象> 數組 |
匹配elementParent下的子元素elementChild。例如:$("div>p") 選擇所有上級元素為div的p元素 |
|
prev+next |
返回: 對象> 數組 |
匹配prev同級之后緊鄰的元素next。例如:$("h1+div") 選擇所有div同級之前為h1的元素() |
|
prev ~ siblings |
返回: 對象> 數組 |
匹配prev同級之后的元素siblings。例如:$("h1~div") 可以匹配() |
基本濾鏡
:first |
返回: 對象> |
匹配第一個元素 |
|
:last |
返回: 對象> |
匹配最后一個元素 |
|
:not(selector) |
返回: 對象> 數組 |
匹配不滿足selector的元素 |
|
:has(selector) |
返回: 對象> 數組 |
匹配包含滿足selector的元素。此選擇器為1.2新增 |
|
:even |
返回: 對象> 數組 |
從匹配的元素集中取序數為偶數的元素。 |
|
:odd |
返回: 對象> 數組 |
從匹配的元素集中取序數為奇數的元素。 |
|
:eq(index) |
返回: 對象> 數組 |
從匹配的元素集中取第index個元素 |
|
:gt(index) |
返回: 對象> 數組 |
從匹配的元素中取序數大于index的元素 |
|
:lt(index) |
返回: 對象> 數組 |
從匹配的元素中取序數小于index的元素 |
|
:header |
返回: 對象> 數組 |
匹配所有的標題元素,例如h1,h2,h3……hN。此選擇器為1.2新增 |
|
:animated |
返回: 對象> 數組 |
匹配正在執行動畫的元素。此選擇器為1.2新增 |
|
:empty |
返回: 對象> 數組 |
匹配所有沒有子元素(包括文本內容)的元素 |
|
:parent |
返回: 對象> 數組 |
匹配包含子元素(包含文本內容)的所有元素 |
|
:contains(text) |
返回: 對象> 數組 |
匹配所有含有text的元素 |
|
:hidden |
返回: 對象> 數組 |
匹配所有隱藏的元素,包含屬性type值為hidden的元素 |
|
:visible |
返回: 對象> 數組 |
匹配所有非隱藏的元素 |
子元素濾鏡
E:nth-child(index/even/odd/equation) |
返回: 對象> 數組 |
匹配所有E在其父元素下滿足(index/even/odd/equation)條件的集合。注:下標從1開始 |
|
E:first-child |
返回: 對象> 數組 |
匹配所有E在其父元素下是第一個子元素的集合。例如:HTML("),使用$("p:first-child"),選取: |
|
E:last-child |
返回: 對象> 數組 |
匹配所有E在其父元素下是最后一個子元素的集合。例如:同上的HTML,使用$("p:last-child"),選取: |
|
E:only-child |
返回: 對象> 數組 |
匹配所有E是其父元素的唯一子元素的集合。例如:同上的HTML,使用$("p:only-child"),選取: |
表單濾鏡
:input |
返回: 對象> 數組 |
匹配所有的input、textarea、select、button |
|
:text |
返回: 對象> 數組 |
匹配文本域。注:在IE瀏覽器下,選擇的對象是所有type屬性為text的元素,在非IE瀏覽器下,選擇的對象是input元素type屬性為text的元素 |
|
:password |
返回: 對象> 數組 |
匹配密碼域。注:在IE瀏覽器下,選擇的對象是所有type屬性為password的元素,在非IE瀏覽器下,選擇的對象是input元素type屬性為password的元素 |
|
:radio |
返回: 對象> 數組 |
匹配單選按鈕。注:在IE瀏覽器下,選擇的對象是所有type屬性為radio的元素,在非IE瀏覽器下,選擇的對象是input元素type屬性為radio的元素 |
|
:checkbox |
返回: 對象> 數組 |
匹配復選框。注:在IE瀏覽器下,選擇的對象是所有type屬性為checkbox的元素,在非IE瀏覽器下,選擇的對象是input元素type屬性為checkbox的元素 |
|
:submit |
返回: 對象> 數組 |
匹配提交按鈕。注:在IE瀏覽器下,選擇的對象是所有type屬性為submit的元素,在非IE瀏覽器下,選擇的對象是input元素type屬性為submit的元素和button元素type屬性為空或為submit的元素 |
|
:image |
返回: 對象> 數組 |
匹配圖像域。注:在IE瀏覽器下,選擇的對象是所有type屬性為image的元素,在非IE瀏覽器下,選擇的對象是input元素type屬性為image的元素 |
|
:reset |
返回: 對象> 數組 |
匹配重置按鈕。注:在IE瀏覽器下,選擇的對象是所有type屬性為reset的元素,在非IE瀏覽器下,選擇的對象是input或button元素type屬性為reset的元素 |
|
:button |
返回: 對象> 數組 |
匹配按鈕。注:在IE瀏覽器下,選擇的對象是所有type屬性為button的元素和元素名為button的元素,在非IE瀏覽器下,選擇的對象是input元素type屬性為button的元素和元素名為button的元素 |
|
:file |
返回: 對象> 數組 |
匹配文件域。注:在IE瀏覽器下,選擇的對象是所有type屬性為file的元素,在非IE瀏覽器下,選擇的對象是input元素type屬性為file的元素 |
|
:enabled |
返回: 對象> 數組 |
匹配所有可用的元素。注:即:not(:disabled),參考:disabled的注釋 |
|
:disabled |
返回: 對象> 數組 |
匹配所有禁用的元素。注:在非IE瀏覽器下,選擇的對象是禁用的表單元素 |
|
:checked |
返回: 對象> 數組 |
匹配所有被選中的表單。注:在IE瀏覽器下,選擇的對象是含有checked屬性的所有元素 |
|
:selected |
返回: 對象> 數組 |
匹配所有選擇的表單。注:在IE瀏覽器下,選擇的對象是含有selected屬性的所有元素 |
屬性濾鏡
[attribute] |
返回: 對象> 數組 |
匹配擁有attribute屬性的元素 |
|
[attribute=value] |
返回: 對象> 數組 |
匹配屬性attribute為value的元素 |
|
[attribute!=value] |
返回: 對象> 數組 |
匹配屬性attribute不為value的元素 |
|
[attribute^=value] |
返回: 對象> 數組 |
匹配屬性attribute的值以value開始的元素 |
|
[attribute$=value] |
返回: 對象> 數組 |
匹配屬性attribute的值以value結尾的元素 |
|
[attribute*=value] |
返回: 對象> 數組 |
匹配屬性attribute的值包含value的元素 |
|
[selector1][selector2][selectorN] |
返回: 對象> 數組 |
匹配滿足屬性選擇器selector1、selector2、selectorN的元素 |
熱榜
這個熱榜展示了最常用選擇器的排名,數據是根據使用jQuery的著名網站分析得來的。熱榜中的選擇器已被歸類(如,'div span'和'ul li'都是'tag tag'形式)。紅色部分表示與W3C規范不兼容。% Used一欄表示選擇器使用百分比(# of Uses一欄表示選擇器使用次數)。只用過一次的選擇器沒在熱榜中羅列。
% Used |
# of Uses |
|
#id |
51.290% |
1431 |
.class |
13.082% |
365 |
tag |
6.416% |
179 |
tag.class |
3.978% |
111 |
#id tag |
2.151% |
60 |
tag#id |
1.935% |
54 |
#id:visible |
1.577% |
44 |
#id .class |
1.434% |
40 |
.class .class |
1.183% |
33 |
* |
0.968% |
27 |
#id tag.class |
0.932% |
26 |
#id:hidden |
0.789% |
22 |
tag[name=value] |
0.645% |
18 |
.class tag |
0.573% |
16 |
[name=value] |
0.538% |
15 |
tag tag |
0.502% |
14 |
#id #id |
0.430% |
12 |
#id tag tag |
0.358% |
10 |
tag[name$=value] |
0.323% |
9 |
#id :checkbox |
0.323% |
9 |
#id #id :selected |
0.287% |
8 |
.class tag.class |
0.287% |
8 |
tag#id > tag |
0.287% |
8 |
tag, tag |
0.251% |
7 |
tag.class tag |
0.251% |
7 |
tag .class |
0.215% |
6 |
:radio |
0.215% |
6 |
#id, #id, #id |
0.215% |
6 |
#id .class tag |
0.215% |
6 |
:text |
0.215% |
6 |
tag, tag, tag |
0.215% |
6 |
.class .class .class |
0.215% |
6 |
#id tag[name=value] |
0.179% |
5 |
:checkbox |
0.179% |
5 |
tag[name*=value] |
0.179% |
5 |
#id, #id |
0.179% |
5 |
tag.class tag.class tag |
0.143% |
4 |
tag.class .class |
0.143% |
4 |
tag:selected |
0.143% |
4 |
.class .class .class tag |
0.143% |
4 |
.class.class |
0.143% |
4 |
tag:file |
0.143% |
4 |
tag, tag[name=value] |
0.143% |
4 |
#id, tag[name$=value] |
0.143% |
4 |
tag[name!=value] |
0.143% |
4 |
.class .class tag + .class |
0.108% |
3 |
.class .class tag:gt(2) |
0.108% |
3 |
tag:submit, tag:image, tag:submit |
0.108% |
3 |
tag.class tag.class tag.class tag.class tag.class tag.class |
0.108% |
3 |
#id tag tag.class tag.class tag |
0.108% |
3 |
:input |
0.108% |
3 |
tag.class tag.class |
0.108% |
3 |
.class .class tag:has(tag[name^=value]) |
0.108% |
3 |
#id tag.class tag |
0.108% |
3 |
tag:eq(0) |
0.108% |
3 |
#id :input |
0.108% |
3 |
tag#id tag#id tag |
0.108% |
3 |
.class, .class |
0.108% |
3 |
tag:eq(1) |
0.108% |
3 |
tag#id tag |
0.108% |
3 |
.class tag#id |
0.072% |
2 |
#id tag:first |
0.072% |
2 |
#id tag tag[name!=value] |
0.072% |
2 |
.class #id tag tag |
0.072% |
2 |
tag#id tag.class |
0.072% |
2 |
tag:filled |
0.072% |
2 |
tag:first |
0.072% |
2 |
.class tag tag.class |
0.072% |
2 |
#id tag.class tag tag.class |
0.072% |
2 |
tag.class tag.class tag.class |
0.072% |
2 |
#id #id #id tag.class |
0.072% |
2 |
tag[name$=value], #id |
0.072% |
2 |
tag tag tag |
0.072% |
2 |
:submit, tag:image |
0.072% |
2 |
.class .class tag |
0.072% |
2 |
[name=value]:first |
0.072% |
2 |
.class .class, #id |
0.072% |
2 |
#id .class tag.class |
0.072% |
2 |
.class #id .class |
0.072% |
2 |
#id #id tag tag |
0.072% |
2 |
tag[name] |
0.072% |
2 |
tag, tag, tag, tag |
0.072% |
2 |
tag#id tag#id tag.class |
0.072% |
2 |
tag:unchecked |
0.072% |
2 |
#id .class.class |
0.072% |
2 |
#id tag.class tag > tag |
0.072% |
2 |
.class tag tag tag |
0.072% |
2 |
tag.class:first |
0.072% |
2 |
.class tag.class tag |
0.072% |
2 |
tag#id tag.class:first |
0.072% |
2 |
#id tag.class tag.class tag |
0.072% |
2 |
.class tag tag |
0.072% |
2 |
#id .class tag tag |
0.072% |
2 |
#id tag tag#id |
0.072% |
2 |
tag.class > tag |
0.072% |
2 |
#id .class * |
0.072% |
2 |
:input:visible |
0.072% |
2 |
#id .class .class |
0.072% |
2 |
#id > tag > tag > tag > tag > tag |
0.072% |
2 |
#id tag.class tag tag:gt(0) |
0.072% |
2 |
.class, .class, .class |
0.072% |
2 |
#id #id * |
0.072% |
2 |
#id > *:not(#id) |
0.072% |
2 |
#id tag[name^=value] |
0.072% |
2 |
.class tag.class |
0.072% |
2 |
tag:blank |
0.072% |
2 |