生活随笔
收集整理的這篇文章主要介紹了
jQuery教程08-属性筛选选择器
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
jQuery選擇器之屬性篩選選擇器
屬性選擇器讓你可以基于屬性來定位一個元素??梢灾恢付ㄔ撛氐哪硞€屬性,這樣所有使用該屬性而不管它的值,這個元素都將被定位,也可以更加明確并定位在這些屬性上使用特定值的元素,這就是屬性選擇器展示它們的威力的地方。
描述如下:
瀏覽器支持:
- [att=val]、[att]、[att|=val]、[att~=val] 屬于CSS 2.1規范
- [ns|attr]、[att^=val]、[att*=val]、[att$=val] 屬于CSS3規范
- [name!=“value”] 屬于jQuery 擴展的選擇器
注意:在這么多屬性選擇器中[attr=“value”]和[attr*=“value”]是最實用的。
[attr=“value”]能幫我們定位不同類型的元素,特別是表單form元素的操作,比如說:input[type=“text”],input[type=“checkbox”]等。
[attr*=“value”]能在網站中幫助我們匹配不同類型的文件。
<!DOCTYPE html>
<html><head><meta http-equiv="Content-type" content="text/html; charset=utf-8" /><title></title><link rel="stylesheet" href="imooc.css" type="text/css"><script src="http://libs.baidu.com/jquery/1.9.1/jquery.js"></script><style>.left {width: auto;height: 120px;}.left div {width: 100px;height: 70px;padding: 5px;margin: 5px;float: left;background: #bbffaa;border: 1px solid #ccc;}.bottom {width: 800px;}.bottom div,.bottom span {display: block;width: 80px;height: 80px;margin: 5px;background: #bbffaa;float: left;font-size: 14px;}.bottom .small {width: 60px;height: 25px;font-size: 12px;background: #fab;}</style>
</head><body><h2>屬性篩選選擇器
</h2><h3>[att=val]、[att]、[att|=val]、[att~=val]
</h3><div class="left" testattr="true" ><div class="div" testattr="true" name='p1'><a>[att=val]
</a></div><div class="div" testattr="true" p2><a>[att]
</a></div><div class="div" testattr="true" name="-"><a>[att|=val]
</a></div><div class="div" testattr="true" name="a b"><a>[att~=val]
</a></div></div><script type="text/javascript">$('div[name=p1]').css("border", "3px groove red"); </script><script type="text/javascript">$('div[p2]').css("border", "3px groove blue"); </script><script type="text/javascript">$('div[name|="-"]').css("border", "3px groove #00FF00"); </script><script type="text/javascript">$('div[name~="a"]').css("border", "3px groove #668B8B"); </script><h3>[att^=val]、[att*=val]、[att$=val]、[att!=val]
</h3><div class="left" testattr="true" ><div class="div" testattr="true" name='imooc-aaorn'><a>[att^=val]
</a></div><div class="div" testattr="true" name='aaorn-imooc'><a>[att$=val]
</a></div><div class="div" testattr="true" name="attr-test-selector"><a>[att*=val]
</a></div><div class="div" name="a b"><a>[att!=val]
</a></div></div><script type="text/javascript">$('div[name^=imooc]').css("border", "3px groove red"); </script><script type="text/javascript">$('div[name$=imooc]').css("border", "3px groove blue"); </script><script type="text/javascript">$('div[name*="test"]').css("border", "3px groove #00FF00"); </script><script type="text/javascript">$('div[testattr!="true"]').css("border", "3px groove #668B8B"); </script></body>
</html>
總結
以上是生活随笔為你收集整理的jQuery教程08-属性筛选选择器的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。