原谅我的无知,因为我对编程很陌生。我一直在为这个打败我的大脑。谁能告诉我为什么这不起作用?我知道这将是一件愚蠢的事情:
addText(){
document.getElementById("demo").innerHTML = "New Content";
}
<!DOCTYPE html>
<html>
<head>
<title>InnerHTML Example</title>
</head>
<body>
<p id="demo">
<Button onclick="addText()">Change</Button>
Original Content
</p>
</body>
</html>
答案 0 :(得分:1)
您尚未将addTest()
声明为函数。应该是:
<script>
function addTest() {
...
}
</script>
function addText() {
document.getElementById("demo").innerHTML = "New Content";
}
&#13;
<!DOCTYPE html>
<html>
<head>
<title>InnerHTML Example</title>
</head>
<body>
<p id="demo">
<Button onclick="addText()">Change</Button> Original Content
</p>
</body>
</html>
&#13;