本教程操作环境:windows7系统、jquery1.10.2版本、dell g3电脑。
在jquery中,想要查找含某个属性的元素,需要使用属性选择器[attribute]。
而查找不含某个属性的元素,就需要组合一个否定选择器“:not()”或 not()方法。
语法:
:not([attribute])not([attribute])
示例:
<!doctype html><html> <head> <meta charset="utf-8"> <script src="js/jquery-1.10.2.min.js"></script> <script type="text/javascript"> $(document).ready(function() { $("li:not([id])").css("background-color", "#b2e0ff"); $("li").not("[class]").css("background-color", "#ff0307"); }); </script> </head> <body> <html> <body> <div id="choose"> who is your favourite: <ul> <li id="li1">goofy</li> <li id="li2" class="li">mickey</li> <li class="li">pluto</li> </ul> </div> </body> </html> </body></html>
相关教程推荐:jquery视频教程
以上就是jquery怎么查找不含某个属性的元素的详细内容。
