[英]javascript Change page background color with button
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>
document.body.style.background = color;
没什么更多的了,就是这么简单!
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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.