<!DOCTYPE html> <html> <style> .class1 {background-color:red;width:50px;height:50px} .class2 {background-color:blue;width:50px;height:50px} </style> <body> <h1>HTML DOM Attributes</h1> <h2>value() 属性</h2> <div id="myDiv" class="class1"></div> <p>单击按钮可更改第二个属性的值:</p> <button onclick="myFunction()">点击我</button> <script> function myFunction() { document.getElementById("myDiv").attributes[1].value = "class2"; } </script> </body> </html>