老师,帮检查,代码哪里需要改进
<!DOCTYPE html> <html> <head> <title></title> </head> <body> <input type='text' id='num1' /> <select id='operate'> <option value='+'>+</option> <option value="-">-</option> <option value="*">*</option> <option value="/">/</option> </select> <input type='text' id='num2' /> <input type='button' value=' = ' id="btn" /> <input type='text' id='result' /> <script> var oNum1 = document.getElementById('num1'); var oOperate = document.getElementById('operate'); var oNum2 = document.getElementById('num2'); var oBtn = document.getElementById('btn'); var oResult = document.getElementById('result'); oBtn.onclick = function(){ console.log(Number(oNum1.value)) // oResult.value =Number(oNum1.value) + oOperate.value + Number(oNum2.value) switch(oOperate.value){ case '+': oResult.value = Number(oNum1.value) + Number(oNum2.value); break; case '-': oResult.value = Number(oNum1.value) - Number(oNum2.value); break; case '*': oResult.value = Number(oNum1.value) * Number(oNum2.value); break; case '/': oResult.value = Number(oNum1.value) / Number(oNum2.value); break; } } </script> </body> </html>
9
收起
正在回答 回答被采纳积分+1
相似问题
登录后可查看更多问答,登录/注册
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星