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

为什么我这个程序输入加法的话就不能执行,而其他则可以

无法进行加法

提问者:慕侠2458206 2018-04-27 22:44

个回答

  • 超暖系呆少年i
    2018-04-29 18:29:18

    <!DOCTYPE html>

    <html>

     <head>

      <title> 事件</title>  

      <script type="text/javascript">

       function  count(){

       var txt1 = parseInt(document.getElementById("tex1").value);  

        var txt2 = parseInt(document.getElementById("tex2").value); 

        var s = document.getElementById("select").value;

        switch(s)

        {

            case "+":result=(txt1)+(txt2);

            break;

             case "-": result=(txt1)-(txt2);

            break;

             case "*":result=(txt1)*(txt2);

            break;

             case "/": result=(txt1)/txt2);

            break;

        }

        document.getElementById('fruit').value=result;

       }

      </script> 

     </head> 

     <body>

       <input type="text" id="tex1" />  

      <select id="select">  

            <option value="+">+</option>  

            <option value="-">-</option>  

            <option value="*">*</option>  

            <option value="/">/</option>  

      </select>  

      <input type="text" id="tex2" />  

      <input type="button" value=" = " onclick="count()" />  

      <input type="text" id="fruit" onclick="count()" />     

     </body>

    </html>


  • qq_鸭会飞_0
    2018-04-28 15:42:46

    你case '+'那行的parseInt写错了,要细心啊