gpt4 book ai didi

javascript - 使用 HTML 中的按钮单击更改文本

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

我有大约 8 个按钮的列表,这些按钮列出了不同类别的商店(男装、食品、体育等),我想在单击它们时显示每个类别的商店列表,但使用相同的页面的区域。因此,当我单击“食品店”按钮时,它会将“体育用品店”替换为“食品店”。

我怎样才能相当简单地做到这一点? (我是菜鸟,如果可以的话尽量保持简单)

最佳答案

你可以试试这个简单的 javascript 来改变 onclick 的文本

 <div id="chgtext">This is my current text</div>
<a href="#" onclick="document.getElementById('chgtext').innerHTML='Change the text using javascript';">Change text</a> &nbsp; &nbsp;
<a href="#" onclick="document.getElementById('chgtext').innerHTML='Text will be changed based on the other text';">Change text2</a>&nbsp; &nbsp;
<a href="#" onclick="document.getElementById('chgtext').innerHTML='This is another sample changed text on click the onther text';">Change text3</a>&nbsp; &nbsp;
</div>

关于javascript - 使用 HTML 中的按钮单击更改文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49999660/

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