學齋隨筆,初九潛龍勿用,-14 簡易計算器
阿新 • • 發佈:2019-01-04
1 <!doctype html> 2 <html> 3 <head> 4 <meta charset="utf-8"> 5 <title>無標題文件</title> 6 <link rel="stylesheet" type="text/javascript" href="../js/jisuanqi.js"> 7 </head> 8 9 <body> 10 <div> 11 請輸入數字1 12 <input type="text"id = "sz1"> 13 </div> 14 <div> 15 請輸入數字2 16 <input type="text" id = "sz2"> 17 </div> 18 <div> 19 符號: 20 <select id="fuhao"> 21 <option>+</option> 22 <option>-</option> 23<option>*</option> 24 <option>/</option> 25 </select> 26 </div> 27 <div> 28 <input type="button" onClick="jisuan()" value="結果"> 29 <span id="jieguo"></span> 30 </div> 31 </body>32 </html> 33 <script> 34 function jisuan(){ 35 var n1 = document.getElementById("sz1").value; 36 var n2 = document.getElementById("sz2").value; 37 var fuhao = document.getElementById("fuhao").value; 38 document.getElementById("jieguo").innerHTML = eval(n1+fuhao+n2); 39 } 40 </script>