function count(){
var num1=document.getElementById("txt1").valne;
var num2=document.getElementById("txt2").value;
var sel=document.getElementById("select").value;
var result=document.getElementById("fruit").value;
switch(sel){
case "+":
result=parseInt(num1)+parseInt(num2);
break;
case "-":
result=parseInt(num1)-parseInt(num2);
break;
case "*":
result=parseInt(num1)*parseInt(num2);
break;
case "/":
result=parseInt(num1)/parseInt(num2);
}
}
<script type="text/javascript">
function count() {
//获取第一个输入框的值
var para1 = parseInt(document.getElementById("txt1").value);
//获取第二个输入框的值
var para2 = parseInt(document.getElementById("txt2").value);
//获取选择框的值
var sign = document.getElementById("select").value;
//获取通过下拉框来选择的值来改变加减乘除的运算法则
var result;
switch (sign) {
case '+':
result = para1 + para2;
break;
case '-':
result = para1 - para2;
break;
case '*':
result = para1 * para2;
break;
case '/':
result = para1 / para2;
break;
}
//设置结果输入框的值
document.getElementById("fruit").value = result;
}
</script>
第一行 var num1=document.getElementById("txt1").valne; valne改为value