常用jQuery選取器總結 (二)

來源:互聯網
上載者:User

標籤:

基本元素選取器

 

代碼如下:
$("p")
$("p.ii")選取所有class=ii的 p元素
$("p#demo")選取id=demo的第一個p元素

 

分層選取器

 

代碼如下:
$("div input")div 下的所有input
$("div>input")

 

基本條件選取器

 

代碼如下:
$("p:first")
$("p:last")
$("tr:even")選擇偶數行
$("tr:odd")奇數
$("input:not(:checked)")選擇所有為本選中的元素
$("tr:eq(1)")索引值為1的表格
$("tr:gt(0)")大於0
$("tr:lt(0)")小於0
$(":header")選擇所有標題元素
$(":animated")正在執行的動畫

 

內容條件選取器

 

代碼如下:
$("div:constains(‘ddd‘)")選擇包含ddd文本的層元素
$("td:empty")選擇不包含文本或者子項目的表格單元
$("div:has(p)")選擇包含段落元素的層元素
$("td:parent")選擇包含子項目或者文本的表格單元

 

可見度條件選取器

 

代碼如下:
$("tr:hidden")  //選擇所有隱藏的表格
$("tr:visible") 選擇所有可見的表格

 

屬性選取器

 

代碼如下:
$("div[id]")具有id屬性的層
$("input[name=‘‘]") input屬性name=‘‘
$("input[name!=‘‘]")
$("input[name^=‘‘]")選擇具有name屬性並且值為‘‘為起始內容的表單輸入元素
$("input[name$=‘‘]")選擇具有name屬性並且值為‘‘為結束內容的表單輸入元素
$("input[name*=‘‘]")選擇具有name屬性並且值為‘‘的表單輸入元素
$("input[id][name$=‘‘]")選擇具有id和name屬性的值以‘‘為結束內容的輸入表單元素

 

子項目選取器

 

代碼如下:
$("ul li:nth-child(2)")選擇第二個清單項目
$("ul li:nth-child(even)")
$("ul li:nth-child(odd)")
$("ul li:nth-child(3n)")
$("ul li:first-child")
$("ul li:last-child")
$("ul li:only-child")挑選清單出現且僅出現一個清單項目

 

表單元素選取器

 

代碼如下:
$("input")選擇所有 input textarea select button等元素
$(":text")文本行
$(":password")
$(":radio")
$(":checkbox")
$(":submit")
$(":image")
$(":reset")
$(":button")
$(":file")
$(":hidden")

 

表單屬性選取器

 

代碼如下:
$("input:enabled")  //選擇所有可用
$("input:disabled")
$("input:checked")
$("select:option:selected")

常用jQuery選取器總結 (二)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.