<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>动态改变样式</title> <script> var style={ color:"blue", backgroundColor:"green", borderWidth:"2px" }; function getElement(_elementID) { this._element=document.getElementById(_elementID); } function setStyle(divID) { var element =new getElement(divID); var _element =element._element; for(var p in style) { _element.style[p]=style[p]; } var textStyle=element.style; } </script> </head> <body> <button onclick="setStyle('div1');" >changeStyle</button> <div id="div1">haahddddddd</div> </body> </html>