第一种方法
<style type="text/css" id="theme"> .skin{ width:60px;color:#ff0000; } .skin2{ width:80px;color:#008000; } .layout{ width:260;height:40px;color:#fff; } </style> <div id="test" class="skin">test skin</div> <script type="text/javascript"> var test = document.getElementById('test'); test.className = 'skin2'; </script>
第二种方法
<style type="text/css" id="theme"> .skin{ width:60px;color:#ff0000; } .skin2{ width:80px;color:#008000; } .layout{ width:260;height:40px;color:#fff; } </style> <div id="test" class="skin">test skin</div> <script type="text/javascript"> var test = document.getElementById('test'); test.style.cssText = 'width:50px;color:green'; </script>