2013-04-05 74 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>