<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style>
*{,margin: 0;padding: 0;}
.center{width: 600px;height: 600px;background-color: #fff;border-radius:50% ;margin: auto;}
.center h1{font: #495678,30px;margin-top: 20px;padding-top: 50px;
display: block;text-align: center;text-decoration: none;}
.biao{width: 280px;background-color: #495678;box-shadow: 4px 4px #3d4a65;
margin: 40px auto;padding: 40px 0 30px 40px;}
.btn{outline: none;cursor: pointer;font-size: 20px;width: 45px;height: 45px;
margin: 5px 0 5px 10px;}
.number{background-color: #72778b;box-shadow: 0 5px #5f6680;font: #dededc;border-radius: 50%;border: 0px;}
.operator{background-color: #dededc;box-shadow: 0 5px #bebebe ;font: #72778b;border-radius: 50%;border: 0px;}
.other{background-color: #e3844c;box-shadow: 0 5px #e76a3d ;font:#deded;border-radius: 50%;border: 0px;}
btn:first-child{margin: 5px 0 5px 10px;}
.biao{border-radius: 10%;border: 25px;}
.text{background-color: #98d1dc;box-shadow: inset 6px 6px 0px #3facc0;
font: #dededc;font-size: 20px;height: 47px;width: 165px;
text-align: right;padding-right: 10px;margin-left: 10px;}
</style>
</head>
<body>
<script>
function getValue(x){
document.getElementById("display").value+=x
}
function cls(){
document.getElementById("display").value="";
}
function calc(){
var res=document.getElementById("display").value;
document.getElementById("display").value="";
document.getElementById("display").value=eval(res);
}
</script>
<div class="center">
<h1>HTML+CSS+JS计算器的实现</h1>
<form class="biao">
<input type="button" value="C" id="clear" class="btn other" onclick="cls()"/>
<input type="text" id="display" class="text"/>
<br />
<input type="button" value="7" class="btn number" onclick="getValue(this.value)"/>
<input type="button" value="8" class="btn number" onclick="getValue(this.value)"/>
<input type="button" value="9" class="btn number" onclick="getValue(this.value)"/>
<input type="button" value="+" class="btn operator" onclick="getValue(this.value)"/>
<br />
<input type="button" value="4" class="btn number" onclick="getValue(this.value)"/>
<input type="button" value="5" class="btn number" onclick="getValue(this.value)"/>
<input type="button" value="6" class="btn number" onclick="getValue(this.value)"/>
<input type="button" value="*" class="btn operator" onclick="getValue(this.value)"/>
<br />
<input type="button" value="1" class="btn number" onclick="getValue(this.value)"/>
<input type="button" value="2" class="btn number" onclick="getValue(this.value)"/>
<input type="button" value="3" class="btn number" onclick="getValue(this.value)"/>
<input type="button" value="-" class="btn operator" onclick="getValue(this.value)"/>
<br />
<input type="button" value="0" class="btn number" onclick="getValue(this.value)"/>
<input type="button" value="." class="btn operator" onclick="getValue(this.value)"/>
<input type="button" value="/" class="btn operator" onclick="getValue(this.value)"/>
<input type="button" value="=" class="btn other" onclick="calc()"/>
</div>
</form>
</div>
</body>
</html>
07-03
1万+
03-31
1万+