javascript javascript使用按钮更改页面背景颜色
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15824504/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
javascript Change page background color with button
提问by Velija daviiii
I am trying to figure out how to do code for changing the background color of a page with a button
我想弄清楚如何使用按钮更改页面背景颜色的代码
so basically I have the code for a button written out and its function but im having trouble figuring out what code to use to make the button change the color of the entire page
所以基本上我已经写出了按钮的代码及其功能,但我无法弄清楚使用什么代码来使按钮改变整个页面的颜色
<script>
function changeColor()
{
};
function changeText()
{
alert ("change text in this part");
};
function sendMsg()
{
alert ("change msg content here");
}
</script>
<body>
<h1>Welcome to my program!</h1>
<button onclick="changeColor()">Color</button>
<button onclick="changeText()">Text</button> </br>
<p>Can I ask you something Ive always wanted to ask the real Batman?</p> </br>
<input type="text" name="">
</body>
采纳答案by What have you tried
document.body.style.background = color;
There's not much more to it, it's as simple as that!
没有更多的东西,就是这么简单!
回答by VIKASH TIWARI
Try out this code my dear :
亲爱的试试这个代码:
<FORM>
<INPUT type="button" value="Change to Yellow!" name="button3" onClick="document.bgColor='yellow'"> <br>
<INPUT type="button" value="Change to Red!" name="button4" onClick="document.bgColor='red'"> <br>
<INPUT type="button" value="Change back!" name="button5" onClick="document.bgColor='white'"> </FORM>