点击按钮变换颜色
<!DOCTYPE html> <!--suppress ALL --> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <style> div { width: 200px; height: 400px; background-color: forestgreen; } </style> </head> <body> <input type="button" value="点击" id="btn"> <div id="dv"> </div> <script> document.getElementById("btn").onclick = function () { document.getElementById("dv").style.backgroundColor = "yellow"; }; </script>