<分区>
我是 JavaScript 的初学者。我一直在尝试使用以下两个应该由单击按钮触发的函数来更改 HTML 内容:
<body>
<p id="demo">This is a demonstration.</p>
<button onclick="myFunction()">Click Me!</button>
<p id="demo2">JavaScript can change the style of an HTML element.</p>
<button onclick="myFunction2()">Click me!</button>
<script>
function myFunction() {
document.getElementById("demo").innerHTML = "Hello JavaScript!";
}
function myFunction2(){
document.getElementByID("demo2").style.fontSize="25px";
document.getElementByID("demo2").style.color="red";
document.getElementByID("demo2").style.background-color="yellow";
}
</script>
</body>
出于某种原因,我不明白这两个功能不能同时工作,而是分开工作。
非常感谢您!