簡體   English   中英

javascript使用按鈕更改頁面背景顏色

[英]javascript Change page background color with button

我正在嘗試找出如何使用按鈕更改頁面背景色的代碼

所以基本上我已經寫出了按鈕的代碼及其功能,但是我在弄清楚使用什么代碼使按鈕改變整個頁面的顏色時遇到了麻煩

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

沒什么更多的了,就是這么簡單!

親愛的,嘗試一下這段代碼:

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

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM