用统计功能计算机计算js,js实现计算器功能

本文实例为大家分享了js实现计算器功能的具体代码,供大家参考,具体内容如下

知识点

eval() 函数可计算某个字符串,并执行其中的的 JavaScript 代码。

代码如下

js计算器

计算器

.h1{

position: relative;

color:blueviolet;

font-size:50px;

text-align: center;

top:50px;

}

.box{

width:500px;

position: relative;

top: 100px;

left:50%;

margin-left: -250px;

text-align: center;

background: #495678;

padding:80px 0;

border-radius: 20px;

box-shadow: 4px 4px #3d4a65;

}

.btn{

background:rgba(255,192,203,0.8);

border: 1px solid pink;

cursor:pointer;

outline:none;

font-size:30px;

margin:10px 15px;

height: 70px;

width: 70px;

box-shadow: 0 5px #1a1313de;

}

.btn:active{

transform: translateY(2px);

}

.btn:first-child{

margin-left:-300px;

}

#display{

overflow: hidden;

box-sizing: border-box;

padding-right:18px;

text-align: right;

outline: none;

border:1px solid #4caf50;

color:yellow;

font-size: 30px;

width:280px;

position: absolute;

height: 50px;

top:95px;

right:55px;

background-color: #4caf50;

}

#display,.btn,.box{

border-radius:35px;

}

.operator{

background:orange;

}

.other{

background:white;

}

//清空

document.getElementById("clear").addEventListener("click",function(){

document.getElementById("display").value="";

});

//运算

function get(value) {

document.getElementById("display").value+=value;

}

//结果

function calculates() {

var result=0;

result=document.getElementById("display").value;

document.getElementById("display").value = eval(result);

}

效果图

c44884ef965a022b036c0448b11c8ddc.png

781d50c5b0875b51e0cc5792ffc2af7a.png

04afdd28f2352c819fb630a2d2d303d4.png

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值