问答详情
源自:6-11 编程练习

为什么按“=”结果不显示出来呢

 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;
    
   }

提问者:周周周怀瑾 2019-08-01 22:09

个回答

  • 慕村9346380
    2019-08-05 12:02:50

    因为你要在按键那写个onclick调用函数  <input type='button' value=' = ' onclick="count()" />