一些JavaScript代码的问题

时间:2014-01-12 19:35:12

标签: javascript html onclick

我是JavaScript的初学者,我在运行此脚本时遇到问题:

<html>
    <head>
        <title>some tests with javascript</title>
    </head>
    <body>
        <p id="demo">Here I'm testing some code with javascript </p>
        <script >
            function myFunction() {
                x = document.getELementById("demo");
                x.innerHTML = "Hi! my content has been changed ! ^^";
            }
        </script>
        <button type="button" onclick="myFunction()">click me !</button>
    </body>
</html>

为什么单击按钮后demo元素的内容没有变化?

2 个答案:

答案 0 :(得分:4)

您有拼写错误。而不是:

.getELementById    //Here you have L with uppercase, has to be lowercase

这样做

.getElementById    //Check the 'l'

干杯

Fiddle

答案 1 :(得分:1)

更改

x = document.getELementById("demo");

进入

x = document.getElementById("demo");