<script type="text/javascript">function count() {var a = document.getElementById("txt1").value;var type = document.getElementById("select").value;var b = document.getElementById("txt2").value;switch (type) {case type = "+":document.getElementById("fruit").value = parseInt(a) + parseInt(b);break;case type = "-":document.getElementById("fruit").value = parseInt(a) - parseInt(b);break;case type = "*":document.getElementById("fruit").value = parseInt(a) * parseInt(b);break;case type = "/":document.getElementById("fruit").value = parseInt(a) / parseInt(b);break;default:break;}//获取第一个输入框的值//获取第二个输入框的值//获取选择框的值//获取通过下拉框来选择的值来改变加减乘除的运算法则//设置结果输入框的值 }</script>
<script type="text/javascript">
function count(){
//获取第一个输入框的值
var a=document.getElementById("txt1").value;
//获取第二个输入框的值
var b=document.getElementById("txt2").value;
//获取选择框的值
var c=document.getElementById("select").value;
//获取通过下拉框来选择的值来改变加减乘除的运算法则
var d="";
switch(c){
case "+":
//d=a+b;
d=parseInt(a)+parseInt(b);
break;
case "-":
d=a-b;
break;
case "*":
d=a*b;
break;
default :
d=a/b;
}
//设置结果输入框的值
document.getElementById("fruit").value=d;
}
function count(){
var a=document.getElementById("txt1").value;
//获取第一个输入框的值
var b=document.getElementById("txt2").value;
//获取第二个输入框的值
var opera=document.getElementById("select").value;
//获取选择框的值
var c=document.getElementById("fruit").value;
//设置结果输入框的值
switch(opera)
{
case "+":
document.write(c=Number(a)+Number(b));
break;
case "-":
document.write(c=Number(a)-Number(b));
break;
case "*":
document.write(c=Number(a)*Number(b));
break;
case "/":
document.write(c=Number(a)/Number(b));
break;
}
} //获取通过下拉框来选择的值来改变加减乘除的运算法则
拿去消化。不谢