谁能告诉我这样为什么不行
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | <!DOCTYPE html> <html> <head> <title> 事件</title> <script type= "text/javascript" > function count(){ var one,two,sel,fruit,res; //获取第一个输入框的值 one = parseInt(document.getElementById( "txt1" ).value); //获取第二个输入框的值 two = parseInt(document.getElementById( 'txt2' ).value); //获取选择框的值 sel = document.getElementById( "select" ).value; fruit = document.getElementById( "fruit" ).value; //获取通过下拉框来选择的值来改变加减乘除的运算法则 switch (sel){ case '+' : res = one+two; break ; case '-' : res = one-two; break ; case '*' : res = one*two; break ; case '/' : res = one/two; } //设置结果输入框的值 fruit = res; <!-- document.getElementById( 'fruit' ).value = res; --> } </script> </head> <body> <input type= 'text' id= 'txt1' /> <select id= 'select' > <option value= '+' >+</option> <option value= "-" >-</option> <option value= "*" >*</option> <option value= "/" >/</option> </select> <input type= 'text' id= 'txt2' /> <input type= 'button' value= ' = ' onclick= "count()" /> <!--通过 = 按钮来调用创建的函数,得到结果--> <input type= 'text' id= 'fruit' /> </body> </html> |