简单的js计算器实现

<!DOCTYPE html> <html>  <head>  <meta charset="utf-8">    <title></title>  </head>  <body >    <input type='text' />   <select>           <option value='+'>+</option>     <option value="-">-</option>     <option value="*">*</option>     <option value="https://www.jb51.net/">/</option>   </select>   <input type='text' />   <input type='button' value=' = '/>   <!--通过 = 按钮来调用创建的函数,得到结果-->   <input type='text' /> </body>   <script type="text/javascript">   //制做简单计算器     function count() {     var txt1 = document.all.txt1.value;     var txt2 = document.all.txt2.value;     var s=document.all.select.value;     var z;      switch(s){      case "+": z=parseFloat(txt1)+parseFloat(txt2);break;      case "-": z=parseFloat(txt1)-parseFloat(txt2);break; case "*":z=parseFloat(txt1)*parseFloat(txt2);break;      case "https://www.jb51.net/":z=parseFloat(txt1)/parseFloat(txt2);break;       }       document.getElementById("fruit").value=z;       }     </script> </html>

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wzgpwg.html