<!DOCTYPE html>
<html>
<head>
<title>事件</title>
<script type="text/javascript">
function count(){
//第1个输入框
var num1 = document.getElementById("txt1").value;
//运算符
var ysf = document.getElementById("select").value;
//第2个输入框
var num2 = document.getElementById("txt2").value;
//结果框
var fruit = document.getElementById("fruit");
switch(ysf){
case "+":
fruit.value = parseInt(num1)+parseInt(num2);
break;
case "-":
fruit.value = parseInt(num1)-parseInt(num2);
break;
case "*":
fruit.value = parseInt(num1)*parseInt(num2);
break;
case "/":
fruit.value = parseInt(num1)/parseInt(num2);
break;
}
}
</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=' = ' onclick="count()" />
<input type='text' id='fruit' />
</body>
</html>
好厉害啊