qq_慕雪4472241
2020-03-20 21:35
<script type="text/javascript">
function count(){
//获取第一个输入框的值
var num1 = document.getElementById('txt1').value;
//获取第二个输入框的值
var num2 = document.getElementById("txt2").value;
//获取选择框的值
var sel = document.getElementById("select").value;
//获取通过下拉框来选择的值来改变加减乘除的运算法则
switch(sel){
case '+':
document.getElementById('fruit').value = parseInt(num1)+parseInt(num2);
break;
case '-':
document.getElementById('fruit').value = parseInt(num1)-parseInt(num2);
break;
case '*':
document.getElementById('fruit').value = parseInt(num1)*parseInt(num2);
break;
default '/':
document.getElementById("fruit").value = parseInt(num1)/parseInt(num2);
}
d1 = document.getElementById("txt1").value;
d2 = document.getElementById("txt2").value;
switch(document.getElementById("select").value){
case "+":
document.getElementById("fruit").value = parseInt(d1) + parseInt(d2);
break;
case "-":
document.getElementById("fruit").value = parseInt(d1) - parseInt(d2);
break;
case "*":
document.getElementById("fruit").value = parseInt(d1) * parseInt(d2);
break;
default:
document.getElementById("fruit").value = parseInt(d1) / parseInt(d2);
}
}
default '/'是什么鬼
代码看起来没问题,是不是你等号的onclick调用函数没有成功?
JavaScript进阶篇
468061 学习 · 21891 问题
相似问题