<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>屬性選擇器</title> <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" /> <style type="text/css"> .yang{ border-collapse: collapse; width:500px;height:30px;border:1px solid red;"} </style> <script type="text/javascript" src="jquery-1.7.1.min.js"></script> <script type="text/javascript"> /* [attribute] :匹配具有指定屬性的元素 [attribute=value] :匹配屬性為指定值的元素 [attribute!=value] :匹配屬性值不等於指定值的元素 [attribute^=value] :匹配屬性值以指定值開始的元素 [attribute$=value] :匹配屬性值以指定值結束的元素 [attribute*=value] :匹配屬性值中包含指定值的元素 [selector1][selector2][selectorN] :同時指定多個匹配條件 */ window.onload=function(){ $('#btnOk').click(function(){ //匹配具有color屬性的font並把內容改為jquery $('font[color]').html('jquery'); }); }; </script> </head> <body> <font>字體1</font> <hr /> <font color="#336699">字體2</font> <hr /> <font color="#667788">字體3</font> <hr /> <font color="#338899">字體4</font> <hr /> <font color="#FFAA99">字體5</font> <hr /> <hr/> <input type="button" id='btnOk' value='確定' /> </body> </html>