<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script language="javascript">
function computer()
{
var num1 = document.form1.txtNum1.value;
var num2 = document.form1.txtNum2.value;
var op = document.form1.cho.value;
var arr = new Array("+","-","*","/");
if(num1 == "" || num2 == "")
{
alert("必须输入数据");
}
else if(isNaN(num1) || isNaN(num2))
{
alert("只能输入数字");
}
else if((parseInt(num1)>1000 || parseInt(num1)<1) || (parseInt(num2)>1000 || parseInt(num2)<1))
{
alert("只能输入1~1000的数");
}
else
{
document.form1.txtRes.value = eval(num1 + arr[op] + nun2); //就是最后这里不行
}
}
</script>
</head>
<body>
<form id="form1" name="form1" method="post" action="">
简便计算机:
<input name="txtNum1" type="text" id="txtNum1" size="10" />
<select name="cho" id="cho">
<option value="0" selected="selected">+</option>
<option value="1">-</option>
<option value="2">*</option>
<option value="3">/</option>
</select>
<input name="txtNum2" type="text" id="txtNum2" size="10" />
<input name="btn" type="button" id="btn" value="计 算" onclick="computer()"/>
<input name="txtRes" type="text" id="txtRes" size="10" readonly=""/>
</form>
</body>
</html>
[此贴子已经被作者于2006-8-31 21:20:27编辑过]