<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>Title</title> <script type="text/javascript" src="../js/jquery-3.2.1.min.js"></script> <script> $(function () { //爲包含id屬性的p元素設置顏色屬性 $("p[id]").css("color", "blue"); //爲包含class="222"的p元素設置顏色屬性 $("p[class='222']").css("color", "pink"); //爲包含id屬性且id的屬性值以'a'開頭的span元素設置顏色 $("span[id^='a']").css("color", "green"); //爲包含id屬性且id的屬性值以'g'結尾的span元素設置顏色 $("span[id$='g']").css("color", "red"); //組合屬性包含id='gg'name='11'的span元素設置顏色 $("span[id='gg'][name='11']").css("color", "blue"); //選取屬性id裏包含'123'的span元素設置顏色 $("span[id*='123']").css("color", "purple"); //屬性id!="btn1"裏按鈕設置顏色 $("input[id!='btn1']").css("color",'green'); }) </script></head><body><p id="111">bbbb</p><p id>ccc</p><p class="222">aaaaaaaaaaaaa</p><p class>ddddd</p><span id="a111111">QQQQQQQQQQQ</span><span id="abbb">FFFFFFFFFFFFFF</span><span id="ccccg">HHHHHHHH</span><span id="gg" name="11">TTTTTT</span><span id="123">WWWWWW</span><span id="12345">YYYYYYYY</span><input type="button" id="btn1" value="111"><input type="button" id="btn2" value="222"></body></html>