<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>计算器的实现</title>
</head>
<style type="text/css">
#sDiv {
text-align: center;
border: solid 1px;
width: 300px;
border-radius: 10px;
background-color: aqua;
margin: 20px auto;
background-image: url("http://b-ssl.duitang.com/uploads/item/201506/09/20150609224048_RCQPf.jpeg") ;
}
#t {
border: solid 1px;
width: 260px;
border-radius: 10px;
margin-top: 10px;
margin-bottom: 10px;
font-size: 20px;
}
input[type=button] {
border-radius: 15px;
width: 55px;
height: 30px;
margin: 2px;
font-size: 20px;
}
#equ {
width: 260px;
font-size: 30px;
margin-bottom: 10px;
}
</style>
<body>
<div id="sDiv">
<input type="text" name="t" id="t" value=""/><br/>
<input type="button" name="" value="1" onclick="calCulate(this.value)"/>
<input type="button" name="" value="2" onclick="calCulate(this.value)"/>
<input type="button" name="" value="3" onclick="calCulate(this.value)"/>
<input type="button" name="" value="4" onclick="calCulate(this.value)"/><br/>
<input type="button" name="" value="5" onclick="calCulate(this.value)"/>
<input type="button" name="" value="6" onclick="calCulate(this.value)"/>
<input type="button" name="" value="7" onclick="calCulate(this.value)"/>
<input type="button" name="" value="8" onclick="calCulate(this.value)"/><br/>
<input type="button" name="" value="9" onclick="calCulate(this.value)"/>
<input type="button" name="" value="0" onclick="calCulate(this.value)"/>
<input type="button" name="" value="." onclick="calCulate(this.value)"/>
<input type="button" name="" value="C" onclick="calCulate(this.value)"/><br/>
<input type="button" name="" value="+" onclick="calCulate(this.value)"/>
<input type="button" name="" value="-" onclick="calCulate(this.value)"/>
<input type="button" name="" value="*" onclick="calCulate(this.value)"/>
<input type="button" name="" value="/" onclick="calCulate(this.value)"/><br/>
<input type="button" name="" id="equ" value="=" onclick="calCulate(this.value)"/>
</div>
<script type="text/javascript">
function calCulate(val) {
console.log("===>",val);
var num = document.getElementById("t");
switch (val) {
case "=":
num.value = eval(num.value);
break;
case "C":
num.value = "";
break;
default:
num.value = num.value + val;
break;
}
}
</script>
</body>
</html>
Js实现简单计算器
原创
©著作权归作者所有:来自51CTO博客作者芬月川川的原创作品,请联系作者获取转载授权,否则将追究法律责任
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
Java实现一个简单的计算器
Java编写一个简单的计算器。
System 运算符 字符串 -
JS简单计算器实例
本文实例讲述了JS简单计算器的实现方法。分享给大家供大家参考。具
html javascript d3 -
java实现简单计算器
java实现简单计算器
swing 计算器 -
PHP实现简单计算器
php简单计算器
php html css 计算器