* =运算符用于过滤包含给定值的属性的元素。
您可以尝试运行以下代码,以了解如何* =运算符根据文本过滤属性:
<!DOCTYPE html> <html> <head> <script src="https://cdn.staticfile.org/jquery/3.2.1/jquery.min.js"></script> <script> $(document).ready(function(){ $( "div[myattr*='subject']" ).css("background-color", "yellow"); }); </script> </head> <body> <div myid="sub1" myattr="javasubject">Java</div> <div myid="sub2" myattr="htmlsubject">HTML</div> <div myid="sub3" myattr="ruby">Ruby</div> </body> </html>