我是 Javascript 新手,我按照一个简单的教程创建了一个新手计算器,但是我无法让它工作,也不明白为什么不这样做。
它应该在警告框中显示结果,但事实并非如此。
非常感谢任何帮助/输入,
谢谢
<script type="text/javascript">
var a,b, result;
funciton setValues()
{
a = Number(document.getElementById("a").value);
b = Number(document.getElementById("b").value);
}
function sum() {
setValues();
result = a+b;
alert("The sume is equel to "+result);
}
function rest()
{
setValues();
result = a-b;
alert("The result is equal to "+result);
}
function mult()
{
setValues();
result = a*b;
alert ("The result is equal to "+result);
}
function div()
{
setValues();
result = a/b;
alert ("The result is equal to "+result);
}
</script>
</head>
<body>
<div>
<input id="a" type="text"/>
<input id="b" type="text"/>
<button type="button" onclick="sum()">+</button>
<button type="button" onclick="rest()">-</button>
<button type="button" onclick="mult()"> *</button>
<button type="button" onclick="div()"> /</button>
</div>
</body>