Luffykaiyuan4240471
2017-05-08 23:51
<!DOCTYPE html> <html> <head> <title> 事件</title> <script type="text/javascript"> function count(){ var a = parseInt(document.getElementById("txt1").value); var b = parseInt(document.getElementById("txt2").value); switch(document.getElementById("select").value){ case ("+"): document.write(a+b);break; case ("-"): document.write(a-b);break; case ("*"): document.write(a*b);break; case ("/"): document.write(a/b);break; } } </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=' = '/> <input type='text' id='fruit' onfocus="count()"/> </body> </html>
怎么能够使得点击等于后,结果显示在第三个文本框
switch那一段改成如下试试:
var fruit = document.getElementById( "fruit"); switch(document.getElementById("select").value){ case ("+"): fruit.value=(a+b);break; case ("-"): fruit.value=(a-b);break; case ("*"): fruit.value=(a*b);break; case ("/"): fruit.value=(a/b);break; }
JavaScript进阶篇
468060 学习 · 21891 问题
相似问题