選擇器 | 實例 | 解釋 | |
基本選擇器 | |||
* | $(*) | 選取所有元素 | |
#id | $(“#a”) | 選取id=a的元素 | |
.class | $(“.b”) | 選取class=b的元素 | |
element | $(“p”) | 所有<p>元素 | |
.class.class | $(“.a.b”) | 選取所有class=a且class=b的元素 | |
基本過濾選擇器 | |||
:first | $(“p:first”) | 選取第一個p元素 | |
:last | $(“p:last”) | 選取最后一個p元素 | |
:odd | $(“p:odd”) | 選取所有奇數位上的p元素 | |
:even | $(“p:even”) | 選取所有偶數位上的p元素 | |
:ep(n) | $(“p:eq(n)”) | 選取第n位p元素(index從0開始) | |
:gt(n) | $(“li:gt(n)”) | 選取第n位之前的所有li元素(不包含第n位) | |
:lt(n) | $(“li:lt(n)”) | 選取第n位之后的所有li元素(不包含第n位) | |
:root | $(“p:root”) | 選取p的根元素(不寫標簽時代表選取全局的根元素) | |
:header() | $(“p:header) | 選取P標簽里的所有標題(不寫標簽時代表選取全局的標題) | |
:lang | $(“p:lang(language)”) | 給P標簽選取指定的語言(不寫標簽時代表選取全局的標題) | |
:not | $(“li:not(.active)”) | 選取除了.active以外的元素 | |
:hidden | $(“p:hidden”) | 隱藏所有P標簽 | |
:visible | $(“p:visible”) | 顯示所有p標簽 | |
:target | $(“:target”) | 選取所有目標狀態的元素 | |
:anmated | $(“p:anmated”) | 獲取正在運行的動畫 | |
子元素過濾器 | |||
:first-child | $(“p p:first-last”) | 選取p里第一個標簽為P的子元素 | |
:last-child | $(“p p:last-child”) | 選取p里最后一個為標簽p的子元素(不限位置) | |
:first-of-type | $(“p p:first-of-type”) | 獲取p里出現的第一個p標簽(不限位置) | |
:last-of-type | $(“p p:last-of-type”) | 獲取p里最后出現的p標簽(不限位置) | |
:nth-child(n) | $(“p p:nth-child(2)”) | 獲取p里第二個p標簽(下標從1開始) | |
:nth-of-type(n) | $(“p p:nth-of-type(2)”) | 獲取p里第二個出現的p標簽(下標從0開始) | |
:nth-last-of-type(n) | $(“p p:nth-last-of-type(n)”) | 獲取p里倒數第幾個出現的p標簽 | |
:only-child | $(“p p:only-child”) | 獲取p里唯一一個子元素p | |
:only-of-type | $(“p p:only-of-type”) | 獲取同輩p里唯一一個標簽為p的標簽 | |
:only-of-type(even/odd) | $(“p p:only-of-type(even/odd)”) | 獲取p里所有為奇數或偶數的P標簽(下標從1開始) | |
內容過濾器 | |||
:contains() | $(“p:contains(123)”) | 獲取p標簽里所有包含“123”的標簽 | |
:empty | $(“p:empty”) | 獲取p標簽里沒有內容的所有元素(空格也算內容) | |
:has() | $(“p:has(P)”) | 獲取所有含有p標簽的p | |
:parent | $(“p:parent”) | 獲取所有元素中柚子元素的p(包括文本節點) | |
表單選擇器 | |||
:text | $(“:text”) | 選取所有type為text的字段或type沒有屬性的 | |
:password | $(“:password”) | 選擇所有type為password的 | |
:reset | $(“:reset”) | 選擇所有type為reset(重置)的 | |
:button | $(“:button”) | 選擇所有type為button(按鈕)的 | |
:checkbox | $(“:checkbox”) | 選擇所有type為checkbox(多選)的 | |
:radio | $(“:radio”) | 選擇所有type為radio(單選)的 | |
:file | $(“:file”) | 選擇所有上傳域 | |
:image | $(“:image”) | 選擇所有圖像按鈕 | |
:input | $(“:input”) | 選取所有input、textarea、select、button元素 | |
:enabled | $(“:enabled”) | 選取所有可用的input | |
:disabled | $(“:disabled”) | 選擇所有不可用的input | |
:select | $(“:select”) | 被選中狀態的option元素 | |
:checked | $(“:checked”) | 被選中狀態的input元素(有checked的) | |
:focus | $(“:focus”) | 選取頁面進去就有焦點的input | |
聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com