简易在线计算器 | JavaScript

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>简易在线计算器</title>
</head>
<body>
<script type="text/javascript">
  var numresult;
  var str;
  //让nummessage接收所有数据
  function onclicknum(nums){
    str = document.getElementById("nummessage");
    str.value=str.value + nums;
  }
  //清空显示栏的信息
  function onclickclear(){
  str = document.getElementById("nummessage");
  str.value = "";
  }
  //显示储存的结果;
  function onclickresult(){
  str=document.getElementById("nummessage");
  numresult = eval(str.value);
  str.value=numresult;
  }
</script>
    <div style="font-size:23px; font-size:25px; border:0px;top:0; left:0;bottom:0;right:0;margin:auto  auto">网页版简单计算器</div>
    <table border="2" align="center" bgColor="pink"
            style="height: 350px; width: 270px ;border-collapse:collapse;">
        <tr>
            <td colspan="4" align="center"><input type="text" id="nummessage" style="height: 90px; width: 99.5%; font-size: 50px;border:0px;text-align:right">
            </td>
        </tr>
        <tr>
            <td colspan="2" align="center"><input type="button" id="Del"value="clear" οnclick="onclickclear()" style="height: 70px; width:100%; font-size: 35px">
            </td>
            <td colspan="2"><input  type="button" id="result" value="=" οnclick="onclickresult()" style="height: 70px; width: 100%; font-size: 35px">
            </td>
        </tr>
        <tr>
            <td><input type="button" id="7" value="7" οnclick="onclicknum(7)" style="height: 70px; width: 90px; font-size: 35px">
            </td>
            <td><input type="button" id="8" value="8" οnclick="onclicknum(8)" style="height: 70px; width: 90px; font-size: 35px">
            </td>
            <td><input type="button" id="9" value="9" οnclick="onclicknum(9)" style="height: 70px; width: 90px; font-size: 35px">
            </td>
            <td><input type="button" id="mul" value="*" οnclick="onclicknum('*')" style="height: 70px; width: 90px; font-size: 35px">
            </td>
        </tr>
        <tr>
            <td><input  type="button" id="4" value="4" οnclick="onclicknum(4)" style="height: 70px; width: 90px; font-size: 35px">
            </td>
            <td><input  type="button" id="5" value="5" οnclick="onclicknum(5)" style="height: 70px; width: 90px; font-size: 35px">
            </td>
            <td><input  type="button" id="6" value="6" οnclick="onclicknum(6)" style="height: 70px; width: 90px; font-size: 35px">
            </td>
            <td><input  type="button" id="division" value="/" οnclick="onclicknum('/')" style="height: 70px; width: 90px; font-size: 35px">
            </td>
        </tr>
        <tr>
            <td><input  type="button" id="1" value="1" οnclick="onclicknum(1)" style="height: 70px; width: 90px; font-size: 35px">
            </td>
            <td><input  type="button" id="2" value="2" οnclick="onclicknum(2)" style="height: 70px; width: 90px; font-size: 35px">
            </td>
            <td><input  type="button" id="3" value="3" οnclick="onclicknum(3)" style="height: 70px; width: 90px; font-size: 35px">
            </td>
            <td><input  type="button" id="sub" value="-" οnclick="onclicknum('-')" style="height: 70px; width: 90px; font-size: 35px">
            </td>
        </tr>
        <tr>
            <td colspan="2"><input  type="button" id="0" value="0" οnclick="onclicknum(0)" style="height: 70px; width: 100%; font-size: 35px">
            </td>
            <td><input  type="button" id="."  value="." οnclick="onclicknum('.')" style="height: 70px; width: 90px; font-size: 35px">
            </td>
            <td><input  type="button" id="add" value="+" οnclick="onclicknum('+')" style="height: 70px; width: 90px; font-size: 35px">
            </td>
        </tr>
    </table>
</body>
</html>

展示的效果:

cd6864f43ca74b63305ef0406fafabfe252.jpg

我们来计算下:(6+2)*3/6;

b439113e6ded8788f048e3ec30a8c705c48.jpg

验证一下结果:

f1e0e0d0463175d63aca6cbb4a2f773c78b.jpg

是不是挺好用的呢,一起来做一个吧;

 

 

 

转载于:https://my.oschina.net/u/3995971/blog/2245864

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值