parseFloat(oTxt1) + parseFloat(oTxt2)可以改成parseFloat(oTxt1 + oTxt2)这样吗?
switch(oSlt) {
case "+":
result = parseFloat(oTxt1) + parseFloat(oTxt2);
break;
}
switch(oSlt) {
case "+":
result = parseFloat(oTxt1) + parseFloat(oTxt2);
break;
}
2019-05-07
<script type="text/javascript">
function count(){
var sum=0;
//获取第一个输入框的值
var num1 = document.getElementById("txt1").value;
//获取第二个输入框的值
var num2 = document.getElementById("txt2").value;
//获取选择框的值
var sel = document.getElementById("select").value;
//获取通过下拉框来选择的值来改变加减乘除的运算法则
switch(sel)
{
case '+':sum=parseInt(num1)+parseInt(num2);break;
case '-':sum=parseInt(num1)-parseInt(num2);break;
case '*':sum=parseInt(num1)*parseInt(num2);break;
case '/':sum=parseInt(num1)/parseInt(num2);break;
}
//设置结果输入框的值
var result = document.getElementById("fruit");
result.value=sum;
}
</script>
举报