3 回答
TA贡献5条经验 获得超0个赞
将判断语句改成下面这样:
if(num1 && num2){
switch(rule){
case "+": var result = parseInt(num1) + parseInt(num2);
break;
case "-": var result = num1 - num2;
break;
case "*": var result = num1 * num2;
break;
case "/": var result = num1 / num2;
break;
}
//设置结果输入框的值
document.getElementById("fruit").value = result;
}else if(!num1){
alert("请输入正确的数字!");
document.getElementById("txt1").focus();
return false;
}else if(!num2){
alert("请输入正确的数字!");
document.getElementById("txt2").focus();
return false;
}
}
添加回答
举报