javascript怎么给窗口设置背景颜色?
以下就是完整的HTML页面代码,大家可以测试下。
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Document</title> <style> .big_box{ width: 500px; height: 200px; border: 1px solid black; } .big_box input{ margin-left: 20px; } </style> <script> function Change_red(){ var Red=document.getElementById("change_style"); Red.style.backgroundColor="red"; } function Change_blue(){ var Blue=document.getElementById("change_style"); Blue.style.backgroundColor="blue"; } function Change_green(){ var Green=document.getElementById("change_style"); Green.style.backgroundColor="green"; } function Change_pink(){ var Pink=document.getElementById("change_style"); Pink.style.backgroundColor="pink"; } function Change_black(){ var Black=document.getElementById("change_style"); Black.style.backgroundColor="black"; } </script> </head> <body> <p id="change_style"> <input type="button" value="变为红色" onclick="Change_red()"> <input type="button" value="变为蓝色" onclick="Change_blue()"> <input type="button" value="变为绿色" onclick="Change_green()"> <input type="button" value="变为粉色" onclick="Change_pink()"> <input type="button" value="变为黑色" onclick="Change_black()"> </p> </body> </html>
效果图:
更多web前端知识,请查阅 HTML中文网 !!