【问题标题】:javascript Change page background color with buttonjavascript 使用按钮更改页面背景颜色
【发布时间】:2013-03-27 07:29:38
【问题描述】:

我正在试图弄清楚如何使用按钮更改页面背景颜色的代码

所以基本上我已经写出了一个按钮的代码及其功能,但是我无法弄清楚使用什么代码来使按钮改变整个页面的颜色

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

【问题讨论】:

  • 您可以通过搜索引擎在互联网上获得答案:stackoverflow.com/questions/197748/…
  • 非常感谢,我已经搜索了 45 分钟,每次搜索都让我知道如何更改按钮的颜色而不是背景

标签: javascript button background-color


【解决方案1】:
  document.body.style.background = color;

没什么,就这么简单!

【讨论】:

  • 非常感谢,我之前有那个代码,但每次我尝试它都无法正常执行,我终于弄明白了,谢谢。
【解决方案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>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-06-04
    • 1970-01-01
    • 2013-12-16
    • 1970-01-01
    • 2021-06-22
    • 2015-04-03
    相关资源
    最近更新 更多