gpt4 book ai didi

JavaScript 函数和按钮

转载 作者:行者123 更新时间:2023-11-28 04:45:15 25 4
gpt4 key购买 nike

<分区>

我是 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>

出于某种原因,我不明白这两个功能不能同时工作,而是分开工作。

非常感谢您!

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com