admin管理员组文章数量:1422007
display = document.getElementById('outputDiv');
display.innerHTML = 'Your Number Is: ';
function clear() {
document.getElementById("outputDiv").innerHTML = "";
}
<input type="button" value="Calculate" onclick="calculator()">
<input type="reset" value="Clear" onclick="clear()">
<div id="outputDiv"></div>
display = document.getElementById('outputDiv');
display.innerHTML = 'Your Number Is: ';
function clear() {
document.getElementById("outputDiv").innerHTML = "";
}
<input type="button" value="Calculate" onclick="calculator()">
<input type="reset" value="Clear" onclick="clear()">
<div id="outputDiv"></div>
On the reset button clicked, I would like to erase display.innerHTML='Your Number Is: ' + total;
Share Improve this question edited Nov 23, 2019 at 6:46 connexo 57k15 gold badges111 silver badges147 bronze badges asked Nov 23, 2019 at 6:38 zJqsonzJqson 311 silver badge8 bronze badges 3- what is the issue? doesn't your code working? – Ripa Saha Commented Nov 23, 2019 at 6:43
- I just pasted a part of the code in the website because it won't let me paste the too much in. I have a the math on top of display=. After it printed total. I have a button that is the reset button I want to erase the text that it displayed. – zJqson Commented Nov 23, 2019 at 6:45
- Does this answer your question? Is "clear" a reserved word in Javascript? – FZs Commented Nov 23, 2019 at 7:02
1 Answer
Reset to default 8Do not use clear
as your function name, because due to the inline event listeners' scope, it confuses with the deprecated Document.clear()
.
Try some other name:
<input type="reset" value="Clear" onclick = "clearValue()">
<div id="outputDiv"></div>
<script>
var display = document.getElementById('outputDiv');
var total = 500;
display.innerHTML='Your Number Is: ' + total;
function clearValue() {
display.innerHTML = "";
}
</script>
More: Is “clear” a reserved word in Javascript?
本文标签: javascriptHow do I clear on button clickStack Overflow
版权声明:本文标题:javascript - How do I clear on button click - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745358626a2655192.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论