我是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元素的内容没有变化?
答案 0 :(得分:4)
您有拼写错误。而不是:
.getELementById //Here you have L with uppercase, has to be lowercase
这样做
.getElementById //Check the 'l'
干杯
答案 1 :(得分:1)
更改
x = document.getELementById("demo");
进入
x = document.getElementById("demo");