博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
js制作简单的计算器
阅读量:4706 次
发布时间:2019-06-10

本文共 2044 字,大约阅读时间需要 6 分钟。

学着做了一个简单的计算器!记录记录!哈哈

<!DOCTYPE html>

<html>

<head>

          <title>简单的计算器</title>  

          <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

        <style type="text/css">

              input{width:100%}

      </style>

</head>

<body> 

     <script type="text/javascript">

      function compute(obj)

      {   

       obj.expr.value=eval(obj.expr.value)

      }    

     var plus="+";  

  var minus="-";  

  var multiply="*";

  var divide="/";  

 var decimal=".";

   function enter(obj,string)

 {   

      obj.expr.value+=string;  

}  

function cle(obj)

      {      

   obj.expr.value=''; 

      }  

     </script>

<form >  

<table border=1>

<tr >    

<td colspan="4"><input type="text" name="expr" size="30"  style="width:97%"></td>  

</tr>   

<tr>    

<td><input type="button" value="7" οnclick="enter(this.form,7)"></td>      

<td><input type="button" value="8" οnclick="enter(this.form,8)"></td>      

<td><input type="button" value="9" οnclick="enter(this.form,9)"></td>      

<td><input type="button" value="/" οnclick="enter(this.form,divide)"></td>  

</tr>   

<tr>    

<td><input type="button" value="4" οnclick="enter(this.form,4)"></td>    

<td><input type="button" value="5" οnclick="enter(this.form,5)"></td>   

<td><input type="button" value="6" οnclick="enter(this.form,6)"></td>  

<td><input type="button" value="*" οnclick="enter(this.form,multiply)"</td>  

</tr>  

<tr>      

<td><input type="button" value="1" οnclick="enter(this.form,1)"></td>    

<td><input type="button" value="2" οnclick="enter(this.form,2)"></td>      

<td><input type="button" value="3" οnclick="enter(this.form,3)"></td>     

<td><input type="button" value="-" οnclick="enter(this.form,minus)"></td>   

</tr>

<tr>   

<td colspan="2"><input type="button" value="0" οnclick="enter(this.form,0)"></td>

<td><input type="button" value="." οnclick="enter(this.form,decimal)"></td>  

<td><input type="button" value="+" οnclick="enter(this.form,plus)"></td>  

</tr>      

<tr>     

      <td colspan="2" ><input type="button" value="=" οnclick="compute(this.form)" ></td>    

<td colspan="2"><input type="button" value="AC" size=3 οnclick="cle(this.form)"></td>      

</tr>

</table>

</form>

</body>

</html>

转载于:https://www.cnblogs.com/MinLee/p/5700807.html

你可能感兴趣的文章
POJ 2594 Treasure Exploration (Floyd+最小路径覆盖)
查看>>
数字图像处理 博客目录索引
查看>>
nodejs+redis使用
查看>>
prime算法的使用
查看>>
Jedis - hello world
查看>>
Ehcache(2.9.x) - API Developer Guide, Cache Eviction Algorithms
查看>>
把最近这些安全的问题整理一下
查看>>
【转】如何避免OOM总结
查看>>
java 类与对象
查看>>
git push 每次都要输入用户名密码
查看>>
远程桌面无法复制粘贴
查看>>
对错排认识。
查看>>
js高级程序设计——数据属性和访问器属性
查看>>
ArcGIS客户端API中加载大量数据的几种解决办法(以Silverlight API为例)
查看>>
C# App.config 自定义 配置节
查看>>
Windows PowerShell
查看>>
几道前端的面试题
查看>>
进程间通信的四种方式
查看>>
Sentinel系统监控Redis主从节点
查看>>
Java设计模式之《享元模式》及应用场景
查看>>