咩咩咩3124927
2016-09-09 08:21
<!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
JavaScript进阶篇
468192 学习 · 21891 问题
相似问题