javascript - How do I clear on button click - Stack Overflow

display = document.getElementById('outputDiv');display.innerHTML = 'Your Number Is: 

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
Add a ment  | 

1 Answer 1

Reset to default 8

Do 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?

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745358626a4624257.html

相关推荐

  • javascript - How do I clear on button click - Stack Overflow

    display = document.getElementById('outputDiv');display.innerHTML = 'Your Number Is: 

    4小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信