日期:2014-05-16 浏览次数:20476 次
<html> <head> <script src="ec/jquery/jquery-1.3.2.min.js" type="text/javascript"></script> <script type="text/javascript"> function test() { $("div[id^='jq_'][id$='2'],div[id^='jq_'][id$='4']").css("background-color","red"); } </script> </head> <body> <div id="jq_1">jq_1</div> <div id="jq_2">jq_2</div> <div id="jq_12">jq_12</div> <div id="sdf">sdf</div> <div id="jq_3">jq_3</div> <div id="jq_4">jq_4</div> <div id="jq_24">jq_24</div> <input type="button" id="except" value="选择以jq_开头, 2或4结尾的div" onclick="test()" /> </body> </html>
------解决方案--------------------