下面的例子展示了如何在在HTML5中用JQuery设置HTML中Element的颜色。用JQuery 和 CSS()方法 。
?
<!DOCTYPE html> <html> <head> </head> <body> <p id="debug">The quick brown fox gets replaced by jQuery.</p> <input type="button" value="Set color" onclick="btn_click();" /> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js" type="text/javascript"></script> <script type="text/javascript"> function btn_click() { var hex = "#" + Math.round(Math.random() * 0xFFFFFF).toString(16); $("#debug").css("color", hex); } </script> </body> </html>
?
源码下载:
?
changing-an-elements-text-color-using-jquery.zip