JQuery屬性過濾(轉)

來源:互聯網
上載者:User

標籤:使用   strong   html   div   htm   new   jquery   ef   

屬性過濾(Attribute Filters)的內容就是html元素中的屬性

其包括以下幾個選取器:

[attribute]

[attribute=value]

[attribute!=value]

[attribute^=value]

[attribute$=value]

[attribute*=value]

[attributeFilter1][attributeFilter2][attributeFilterN]

[attribute]
用法: $(“div[id]“) ;
說明: 匹配包含給定屬性的元素.例子中是選取了所有帶”id”屬性的div標籤.

[attribute=value]
用法: $(“input[name=‘newsletter‘]“).attr(“checked”, true); 
說明: 匹配給定的屬性是某個特定值的元素.例子中選取了所有 name 屬性是 newsletter 的 input 元素.

[attribute!=value]
用法: $(“input[name!=‘newsletter‘]“).attr(“checked”, true); 
說明: 匹配所有不含有指定的屬性,或者屬性不等於特定值的元素.此選取器等價於:not([attr=value]),要匹配含有特定屬性但不等於特定值的元素,請使用[attr]:not([attr=value]).嗯,之前看到的 :not 派上了用場.

[attribute^=value]
用法: $(“input[name^=‘news‘]“) ;
說明: 匹配給定的屬性是以某些值開始的元素.

[attribute$=value]
用法: $(“input[name$=‘letter‘]“) ;
說明: 匹配給定的屬性是以某些值結尾的元素.

[attribute*=value]
用法: $(“input[name*=‘man‘]“) ;
說明: 匹配給定的屬性是以包含某些值的元素.

[attributeFilter1][attributeFilter2][attributeFilterN]
用法: $(“input[id][name$=‘man‘]“) ;
說明: 複合屬性選取器,需要同時滿足多個條件時使用.是一個組合.這個例子中選擇的是所有含有 id 屬性,並且它的 name 屬性是以 man 結尾的元素.

聯繫我們

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