gpt4 book ai didi

javascript - 制作可点击按钮更改文本

转载 作者:太空宇宙 更新时间:2023-11-03 21:34:21 25 4
gpt4 key购买 nike

源代码链接:http://hexmerchant.github.io/

我希望每次单击此按钮时都显示不同的文本。我正在使用 html、css 和 js。

<button onclick="exploreFunction()">Explore</button>

这就是按钮。这是第一个函数。

function exploreFunction() {
var person = prompt("What is your name", "");

if (person != null) {
document.getElementById("story1").innerHTML =
"-You wake up lying on the ground. You feel a large deposit of energy inside you.";
}
}

我需要做什么才能做到这一点?

这可以帮助很多人。当我在这里四处寻找答案时,我意识到每个答案都非常具体,以至于我找不到与我的主题相匹配的答案。

我对这一切还很陌生,正在努力自学……走到这一步:)

最佳答案

只需为按钮添加一个 ID,例如 -

<button id="myButton" onclick="exploreFunction()">Explore</button>

然后您可以向 exploreFunction() 添加一个与更改文本非常相似的命令 -

document.getElementById("myButton").value = "New display text";

关于javascript - 制作可点击按钮更改文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27589934/

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