所以我正在使用Javascript基本和添加元素,但我有一些打嗝

时间:2015-12-27 19:28:10

标签: javascript

单击按钮时为什么不创建输出? 我有这样的功能才能工作,唯一不同的是改变按钮颜色的Div元素,但无论出于什么原因它似乎都不起作用。我也尝试过玩我能理解的变量,但我不确定,因为我认为他们可能会导致这个问题我只是不知道如何解决这个问题...请帮助我

 <!DOCTYPE html>
    <html>
    <head>
    <meta charset ="utf-8">
    <title>I ROCK YOU MIGHT</title>
    <h1>Lets begin something organized</h1>
    <style>
    #Wrapper{
      background-color:purple;
      text-align:center;
      padding:25px;
    }

    #Wrapper2{
      background-color:red;
      text-align:Left;
      padding:25px;
     }
   </style>
   </head>
   <body>
   <p id="demo">1</p>

    <script>
    var domobject = document.getElementByID("Wrapper");
    var domobejct2 = document.getElelmentById("Wrapper2");
    </script>

    <button onclick="function1">CLICK ME
    <div id= "Wrapper">ELEMENT </div>
    </button>

    <script>
    function function1() {
    document.getElementById("demo").innerHTML = Math.random();
    }
    </script>

    <p id="demo2">3</p>

    <button onclick="function2">CLICKER ME
    <div id="Wrapper2">ELMERHOOD </div>
    </button>
    <script>
    function function2() {
    document.getElementById("demo2").innerHTML = Math.random();
    }
    </script>


    </body>
    </html>

1 个答案:

答案 0 :(得分:1)

为了在click事件中调用一个函数,你必须将其称为function1();

<button onclick="function1();">CLICK ME
    <div id= "Wrapper">ELEMENT </div>
</button>