<!DOCTYPE html> <!--Javascript-DOM操作CSS--> <html> <head lang="en"> <meta charset="UTF-8"> <title></title> <link href="css21.css" type="text/css" rel="stylesheet"> </head> <body> <div id ="div"> 我要改变css </div> <button οnclick="demo()">按钮</button> <script> function demo(){ document.getElementById("div").style.backgroundColor="#b3d4fc"; } </script> </body> </html>
css:
#div{ width: 100px; height: 100px; /*background-color: #b3d4fc;*/ background-color: cadetblue; }