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?
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745358626a4624257.html
评论列表(0条)