<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>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script language="javascript" type="text/javascript">
function result(s){
var num1= parseInt(document.form.num1.value)
var num2= parseInt(document.form.num2.value)
if(s=="+"){
document.form.sum1.value=num1+num2;
}else if(s=="-"){
document.form.sum1.value=num1-num2;
}else if(s=="*"){
document.form.sum1.value=num1*num2;
}else if(s=="/" && num2 !=0){
document.form.sum1.value=num1/num2;
}
}
</script>
</head>
<body>
<form action="" name="form" method="post">
<table width="271" border="1" cellspacing="0" cellpadding="0">
<tr>
<td height="30" colspan="3" align="left" valign="top">计算器</td>
</tr>
<tr align="center">
<td width="107" height="29">第一个数:</td>
<td width="112"><label>
<input name="num1" type="text" id="textfield" size="8" />
</label></td>
<td width="44" rowspan="3"><label>
<input type="button" name="button" id="button" value=" + " onclick="result('+')"/>
</label>
<label>
<input type="button" name="button2" id="button2" value=" - "onclick="result('-')" />
</label>
<label>
<input type="button" name="button3" id="button3" value=" * " onclick="result('*')" />
</label>
<label>
<input type="button" name="button4" id="button4" value=" / " onclick="result('/')" />
</label></td>
</tr>
<tr align="center">
<td height="30">第二个数:</td>
<td><label>
<input name="num2" type="text" id="textfield2" size="8" />
</label></td>
</tr>
<tr align="center">
<td height="21">计算结果:</td>
<td><label>
<input name="sum1" type="text" id="textfield3" size="8" />
</label></td>
</tr>
</table>
</form>
</body>
</html>