html/javascript - 更改标签文本

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19055277/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 14:12:22  来源:igfitidea点击:

html/javascript - Change label text

javascripthtml

提问by Matt9Atkins

Hi I have a label on my page and I want to change the text of that label when a button is pressed. I have used the following code but nothing happens to the label.

嗨,我的页面上有一个标签,我想在按下按钮时更改该标签的文本。我使用了以下代码,但标签没有任何反应。

Javascript:

Javascript:

<script type="text/javascript">
function changePrice(){
    document.getElementById('price11').innerHTML = '2.99';
}
</script>

HTML:

HTML:

<label for="price1" id="price11">5.00</label>
<input type='button' onclick='changePrice()'/>

采纳答案by Matt9Atkins

I have worked around it by having another label with new text. The button hides the old label and shows the new label

我通过使用另一个带有新文本的标签来解决它。按钮隐藏旧标签并显示新标签