清除功能没有做任何事情
Clear function isn't doing anything
我通过 Javascript 制作了一个基本的计算器,所有其他函数(例如加法、减法等)都可以使用,但是清除函数没有任何作用,也没有出现任何错误在开发人员工具中。
我试过保留清除功能,甚至删除评论,但没有任何改变。
//function to clear the numbers together
function clearNumbers() {
// make variable for the value of box1
var value1 = "";
// make a variable for the value of box2
var value2 = "";
// make a variable called total
var total = "";
// put total in the output span
document.getElementById("output").innerHTML = "";
// put a sign in the sign span
document.getElementById("sign").innerHTML = " ";
}
<input type="button" value="Clear" onClick="clearNumbers();">
没有错误消息
您需要设置 document.getElementById("box1").value = "";
以清除文本框值。
//function to divide the numbers together
function divideNumbers() {
// make variable for the value of box1
var value1 = parseFloat(document.getElementById("box1").value);
// make a variable for the value of box2
var value2 = parseFloat(document.getElementById("box2").value);
// make a variable called total
var total = value1 / value2;
// put total in the output span
document.getElementById("output").innerHTML = total;
// put a ÷ sign in the sign span
document.getElementById("sign").innerHTML = "÷";}
//function to clear the numbers together
function clearNumbers() {
// make variable for the value of box1
var value1 = "";
document.getElementById("box1").value = "";
// make a variable for the value of box2
var value2 = "";
document.getElementById("box2").value = "";
// make a variable called total
var total = "";
// put total in the output span
document.getElementById("output").innerHTML = "";
// put a sign in the sign span
document.getElementById("sign").innerHTML = " ";}
<input type='text' id='box1' />
<div id='sign'></div>
<input type='text' id='box2' />
<input type='text' id='output' />
<input type="button" value="Clear" onClick="clearNumbers();">
我通过 Javascript 制作了一个基本的计算器,所有其他函数(例如加法、减法等)都可以使用,但是清除函数没有任何作用,也没有出现任何错误在开发人员工具中。
我试过保留清除功能,甚至删除评论,但没有任何改变。
//function to clear the numbers together
function clearNumbers() {
// make variable for the value of box1
var value1 = "";
// make a variable for the value of box2
var value2 = "";
// make a variable called total
var total = "";
// put total in the output span
document.getElementById("output").innerHTML = "";
// put a sign in the sign span
document.getElementById("sign").innerHTML = " ";
}
<input type="button" value="Clear" onClick="clearNumbers();">
没有错误消息
您需要设置 document.getElementById("box1").value = "";
以清除文本框值。
//function to divide the numbers together
function divideNumbers() {
// make variable for the value of box1
var value1 = parseFloat(document.getElementById("box1").value);
// make a variable for the value of box2
var value2 = parseFloat(document.getElementById("box2").value);
// make a variable called total
var total = value1 / value2;
// put total in the output span
document.getElementById("output").innerHTML = total;
// put a ÷ sign in the sign span
document.getElementById("sign").innerHTML = "÷";}
//function to clear the numbers together
function clearNumbers() {
// make variable for the value of box1
var value1 = "";
document.getElementById("box1").value = "";
// make a variable for the value of box2
var value2 = "";
document.getElementById("box2").value = "";
// make a variable called total
var total = "";
// put total in the output span
document.getElementById("output").innerHTML = "";
// put a sign in the sign span
document.getElementById("sign").innerHTML = " ";}
<input type='text' id='box1' />
<div id='sign'></div>
<input type='text' id='box2' />
<input type='text' id='output' />
<input type="button" value="Clear" onClick="clearNumbers();">