三、jQuery選取器

來源:互聯網
上載者:User

標籤:網頁   元素   jquery   選取器   

注意:

jQuery擷取的永遠是對象,即使網頁上沒有此元素

不能這樣判斷 if($(‘#tt‘)){}

應根據元素長度來判斷 if($(‘#tt‘).length > 0){}

或轉化成DOM來判斷 if($(‘#tt‘)[0]){}


一、基本選取器

基本選取器是jQuery中最常用的選取器,也是最簡單的選取器,它通過元素id,class,和標籤名等來尋找DOM元素。

650) this.width=650;" src="http://s3.51cto.com/wyfs02/M01/37/C8/wKiom1Ov4wzTaKNhAAFZs1AjZjo953.jpg" title="23411234.JPG" alt="wKiom1Ov4wzTaKNhAAFZs1AjZjo953.jpg" />


二、層次選取器


650) this.width=650;" src="http://s3.51cto.com/wyfs02/M02/37/C8/wKiom1Ov4w2S_bG6AAIV7RB4Ft0451.jpg" title="325453453.JPG" alt="wKiom1Ov4w2S_bG6AAIV7RB4Ft0451.jpg" />



三、過濾選取器

1、基本過濾選取器

650) this.width=650;" src="http://s3.51cto.com/wyfs02/M00/37/C7/wKioL1Ov4t-hvwF3AAVOHFdzM0Q176.jpg" title="234234234.png" alt="wKioL1Ov4t-hvwF3AAVOHFdzM0Q176.jpg" />



2、內容過濾選取器


650) this.width=650;" src="http://s3.51cto.com/wyfs02/M01/37/C8/wKiom1Ov4w7zb9SnAAFRsJuhpJU468.jpg" title="內容過濾.JPG" alt="wKiom1Ov4w7zb9SnAAFRsJuhpJU468.jpg" />



3、可見度過濾選取器

650) this.width=650;" src="http://s3.51cto.com/wyfs02/M02/37/C7/wKioL1Ov4t-QoOrHAADvVrvLYmk979.jpg" title="可見度過濾.JPG" alt="wKioL1Ov4t-QoOrHAADvVrvLYmk979.jpg" />


4、屬性過濾選取器

650) this.width=650;" src="http://s3.51cto.com/wyfs02/M00/37/C7/wKioL1Ov4uDCpR4PAAJfIf-62Rg750.jpg" title="屬性過濾.JPG" alt="wKioL1Ov4uDCpR4PAAJfIf-62Rg750.jpg" />


5、子項目過濾選取器

650) this.width=650;" src="http://s3.51cto.com/wyfs02/M02/37/C7/wKioL1Ov5OixLbAtAAYHRKxF9zk126.jpg" title="無標題.png" alt="wKioL1Ov5OixLbAtAAYHRKxF9zk126.jpg" />


 6、表單對象屬性過濾選取器

650) this.width=650;" src="http://s3.51cto.com/wyfs02/M00/37/C8/wKiom1Ov4w7QK8CbAAFSR7MfyhY311.jpg" title="表單元素.JPG" alt="wKiom1Ov4w7QK8CbAAFSR7MfyhY311.jpg" />


 四、表單選取器

650) this.width=650;" src="http://s3.51cto.com/wyfs02/M01/37/C7/wKioL1Ov4t-A_KQpAAJapdcODaU844.jpg" title="表單選擇.JPG" alt="wKioL1Ov4t-A_KQpAAJapdcODaU844.jpg" />

 


五、注意  特殊符號處理

 <div id="id#b">bb</div>

 <div id="id[1]">cc</div>


$(‘#id#b‘)

$(‘#id[1]‘) 不能擷取

要轉義

$(‘#id\\#b‘)

$(‘#id\\[1\\]‘)


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.