<html>
<head>
<meta http-equiv="Content-type" charset="utf-8" type="text/html">
<title>计算器</title>
<script type="text/javascript">
function count(){
var itxt1=document.getElementById("txt1").value;
var itxt2=document.getElementById("txt2").value;
var test=document.getElementById("select").value;
var result="";
switch(test){
case "+":
result=parseFloat(itxt1)+parseFloat(itxt2);
break;
case "-":
result=parseFloat(itxt1)-parseFloat(itxt2);
break;
case "*":
result=parseFloat(itxt1)*parseFloat(itxt2);
break;
default:
result=parseFloat(itxt1)/ parseFloat(itxt2); }
document.getElementById("fruit").value=result;
}
</script>
</head>
<body>
<input type="text" id="txt1">
<select id="select">
<option value="+">+</option>
<option value="-">-</option>
<option value="*">*</option>
<option value="/">/</option>
</select>
<input type="text" id="txt2">
<input type="button" value='=' οnclick="count()"/>
<input type="text" id="fruit">
</body>
<head>
<meta http-equiv="Content-type" charset="utf-8" type="text/html">
<title>计算器</title>
<script type="text/javascript">
function count(){
var itxt1=document.getElementById("txt1").value;
var itxt2=document.getElementById("txt2").value;
var test=document.getElementById("select").value;
var result="";
switch(test){
case "+":
result=parseFloat(itxt1)+parseFloat(itxt2);
break;
case "-":
result=parseFloat(itxt1)-parseFloat(itxt2);
break;
case "*":
result=parseFloat(itxt1)*parseFloat(itxt2);
break;
default:
result=parseFloat(itxt1)/ parseFloat(itxt2); }
document.getElementById("fruit").value=result;
}
</script>
</head>
<body>
<input type="text" id="txt1">
<select id="select">
<option value="+">+</option>
<option value="-">-</option>
<option value="*">*</option>
<option value="/">/</option>
</select>
<input type="text" id="txt2">
<input type="button" value='=' οnclick="count()"/>
<input type="text" id="fruit">
</body>
</html>
注意:数字中出现小数点能,可能会有误差!