html计算器

<!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>

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值