<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
<script>
window.onload = function()
{
var oTxt1 = document.getElementById("txt1");
var oTxt2 = document.getElementById("txt2");
var oSel1 = document.getElementById("sel1");
var oBtn1 = document.getElementById("btn1");
var oSpa1 = document.getElementById("spa1");
oBtn1.onclick=function()
{
var a1 = parseFloat(oTxt1.value);
var a2 = parseFloat(oTxt2.value);
var result;
switch(oSel1.value)
{
case "+":result=a1+a2;
break;
case "-":result=a1-a2;
break;
case "*":result=a1*a2;
break;
case "/":result=a1/a2;
break;
case "%":result=a1%a2;
break;
}
oSpa1.innerHTML = result;
}
}
</script>
</head>
<body>
<input type="text" id="txt1" />
<select id="sel1">
<option value="+">+</option>
<option value="-">-</option>
<option value="*">*</option>
<option value="/">/</option>
<option value="%">%</option>
</select>
<input type="text" id="txt2" />
<input type="button" value="计算" id="btn1" />
<span id="spa1"></span>
</body>
</html>