Here is my code:
<!DOCTYPE html>
<HTML>
<HEAD>
<script>
var a,b,result;
function setValues()
{
a = Number(document.getElementById("a").Value);
b = Number(document.getElementById("b").Value);
}
function sum()
{
setValues();
result = a+b;
alert("The Sum For The Values Is "+result);
}
function multiply()
{
setValues();
result = a*b;
alert("The Product For The Values Is "+result);
}
function div()
{
setValues();
result = a/b;
alert("The Quotient For The Values Is "+result);
}
</script>
</HEAD>
<STYLE>
body
{
background-color: #b0c4de;
}
</STYLE>
<body>
<CENTER>
<H1><B><U> Fun Facts!</B></U></H1>
<H4>Did You Know There Are Over 7 Billion People In The World!!!</H4>
<div>
<input Id="a" Type="Text"/>
<input Id="b" Type="Text"/>
<input Type="Button" onclick="sum()" Value="sum"/>
<input Type="Button" onclick="multiply()" Value="multiply"/>
<input Type="Button" onclick="div()" Value="divide"/>
</div>
</body>
</CENTER>
</HTML>
这是一个简单的计算器,但是当我点击um,乘以或除以时,我得到“NaN错误。我添加警报系统,所以答案是总和,产品或商,然后答案,但我要听警报系统,但结果我得到了NaN 请帮忙。 谢谢
<!DOCTYPE html>
<HTML>
<HEAD>
<script>
var a,b,result;
function setValues()
{
a = Number(document.getElementById("a").Value);
b = Number(document.getElementById("b").Value);
}
function sum()
{
setValues();
result = a+b;
alert("The Sum For The Values Is "+result);
}
function multiply()
{
setValues();
result = a*b;
alert("The Product For The Values Is "+result);
}
function div()
{
setValues();
result = a/b;
alert("The Quotient For The Values Is "+result);
}
</script>
</HEAD>
<STYLE>
body
{
background-color: #b0c4de;
}
</STYLE>
<body>
<CENTER>
<H1><B><U> Fun Facts!</B></U></H1>
<H4>Did You Know There Are Over 7 Billion People In The World!!!</H4>
<div>
<input Id="a" Type="Text"/>
<input Id="b" Type="Text"/>
<input Type="Button" onclick="sum()" Value="sum"/>
<input Type="Button" onclick="multiply()" Value="multiply"/>
<input Type="Button" onclick="div()" Value="divide"/>
</div>
</body>
</CENTER>
</HTML>
答案 0 :(得分:2)
你有一个简单的错误:
function setValues()
{
a = Number(document.getElementById("a").Value);
b = Number(document.getElementById("b").Value);
}
.Value
应为.value
...
来自奥地利的问候