<!doctype html> <html> <head> <meta charset="utf-8"> <title></title> <script> function count(){ var oTxt1=document.getElemnetById("txt1").value; var oTxt2=document.getElemnetById("txt2").value; var oSlt=document.getElemnetById("select").value; var result=""; switch(oSlt) { case "+": result=parseFloat(oTxt1)+parseFloat(oTxt2); break; case "-": result=parseFloat(oTxt1)-parseFloat(oTxt2); break; case "*": result=parseFloat(oTxt1)*parseFloat(oTxt2); break; default: result=parseFloat(oTxt1)/parseFloat(oTxt2); } document.getElemnetById("fruit").value=result; } </script> </head> <body> <input type="text" id="txt1"> <select name="" 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>
getElementById拼错了,不是getElemnetById