<html>
<head>
<title>runcode</title>
<script type = "text/javascript">
function run(t){
var sa = parseInt(document.getElementById('sa').value);
var sb = parseInt(document.getElementById('sb').value);
var sc = document.getElementById('sc');
if(isNaN(sa) || isNaN(sb)){
alert("输入错误,请重新输入!");
return;
}
switch(t){
case 1 :
sc.value = sa + sb;
break;
case 2 :
sc.value = sa - sb;
break;
case 3 :
sc.value = sa * sb;
break;
case 4 :
if(sb == 0){
alert("被除数不能为0!");
return;
}
sc.value = sa / sb;
break;
}
}
</script>
</head>
<body>
<table width="255" height="136" border="1" style="background:#66CCFF; font-size:12px;">
<tr>
<td colspan="3">计算器</td>
</tr>
<tr>
<td width="62" height="34">第一个数</td>
<td width="102"><input name="text" type = "text" id = "sa" width="100px" onclick = "this.value =''" value = ""/></td>
<td width="29" rowspan="3"><input name="button" type = "button" onclick = "run(1)" value = " + " />
<input name="button2" type = "button" onclick = "run(2)" value = " - " />
<input name="button3" type = "button" onclick = "run(3)" value = " * " />
<input name="button4" type = "button" onclick = "run(4)" value = " / " /></td>
</tr>
<tr>
<td height="32">第二个数</td>
<td><input name="text2" type = "text" id = "sb" width="100px" onclick = "this.value =''" value = ""/></td>
</tr>
<tr>
<td>计算结果</td>
<td><input name="text3" type = "text" id = "sc" width="100px" value = ""/></td>
</tr>
</table>
<p> </p>
</body>
</html>
<html>
<head>
<title>runcode</title>
<script type = "text/javascript">
function run(t){
var sa = parseInt(document.getElementById('sa').value);
var sb = parseInt(document.getElementById('sb').value);
var sc = document.getElementById('sc');
if(isNaN(sa) || isNaN(sb)){
alert("输入错误,请重新输入!");
return;
}
switch(t){
case 1 :
sc.value = sa + sb;
break;
case 2 :
sc.value = sa - sb;
break;
case 3 :
sc.value = sa * sb;
break;
case 4 :
if(sb == 0){
alert("被除数不能为0!");
return;
}
sc.value = sa / sb;
break;
}
}
</script>
</head>
<body>
<table width="255" height="136" border="1" style="background:#66CCFF; font-size:12px;">
<tr>
<td colspan="3">计算器</td>
</tr>
<tr>
<td width="62" height="34">第一个数</td>
<td width="102"><input name="text" type = "text" id = "sa" width="100px" onclick = "this.value =''" value = ""/></td>
<td width="29" rowspan="3"><input name="button" type = "button" onclick = "run(1)" value = " + " />
<input name="button2" type = "button" onclick = "run(2)" value = " - " />
<input name="button3" type = "button" onclick = "run(3)" value = " * " />
<input name="button4" type = "button" onclick = "run(4)" value = " / " /></td>
</tr>
<tr>
<td height="32">第二个数</td>
<td><input name="text2" type = "text" id = "sb" width="100px" onclick = "this.value =''" value = ""/></td>
</tr>
<tr>
<td>计算结果</td>
<td><input name="text3" type = "text" id = "sc" width="100px" value = ""/></td>
</tr>
</table>
<p> </p>
</body>
</html>