周周周怀瑾
2019-08-01 22:09
function count(){
var oTxt1 = document.getElementById("txt1").value;
var oTxt2 = document.getElementById("txt2").value;
var oSlt = document.getElementById("select").value;
var result = " ";
switch(oSlt) {
case "+":
result = parseInt(oTxt1) +parseInt(oTxt2);
break;
case "-":
result = parseInt(oTxt1) - parseInt(oTxt2);
break;
case "*":
result = parseInt(oTxt1) * parseInt(oTxt2);
break;
default:
result =parseInt(oTxt1) / parseInt(oTxt2);
}
document.getElementById("fruit").value = result;
}
因为你要在按键那写个onclick调用函数 <input type='button' value=' = ' onclick="count()" />
JavaScript进阶篇
468190 学习 · 21891 问题
相似问题