简单的网页计算器,求指点
<html><head>
<script type="text/javascript">
var ans;
var num1=document.getElementById("n1").value;
var num2=document.getElementById("n2").value;
var op=document.name.value;
function cal(num1,num2,op)
{
if(op=="+")
{ans=num1+num2;
document.getElementBId("answer").innerHTML=ans;
}
else if(op=="*")
{ans=num1*num2;
document.getElementBId("answer").innerHTML=ans;
}
else if(op=="/")
{ans=num1/num2;
document.getElementBId("answer").innerHTML=ans;
}
else
{ans=num1-num2;
document.getElementBId("answer").innerHTML=ans;
}
}
</script>
</head>
<body>
<h1 align="center">This is a web calculator...</h1>
<table>
<tr>
<td>
The left value
</td>
<td>
The operator
</td>
<td>
The right value
</td>
</tr>
<tr>
<td><input type="text" id="n1"></td>
<td><select name="operator">
<option value="+">+</option>
<option value="*">*</option>
<option value="/">/</option>
<option value="-">-</option>
</select>
</td>
<td>
<input type="text" id="n2">
</td>
</table>
<p id="answer">The answer is</p>
<button onclick="cal(num1,num2,op)">sumbit</button>
<button onclick="location.reload()">again</button>
</body>
</html>