2013-04-05 32 views
1

我想弄清楚如何使用按钮来改变页面的背景颜色代码javascript更改页面背景颜色的按钮

所以基本上我有一个代码写出来的按钮和它的功能,但有问题搞清楚用什么代码,以使按钮改变整个页面

<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> 
+0

您可以通过搜索引擎获取互联网上的答案:http://stackoverflow.com/questions/197748/how-do-i-change-the-background -color-with-javascript – 2013-04-05 01:38:12

+0

非常感谢你一直在寻找45分钟,每一次搜索都给我带来了如何改变按钮的颜色,而不是背景 – 2013-04-05 01:47:00

回答

1
document.body.style.background = color; 
颜色IM

没有太多它,它就这么简单!

+0

非常感谢,我之前有过这样的代码,但每次我尝试它不会正确执行,我终于明白了,谢谢。 – 2013-04-05 01:47:30

-2

试试这个代码我亲爱的:

<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>