js+css实现简易计算器

1 篇文章 0 订阅
<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<style>
			.wrapper{
				width: 1000px;
				border: 1px solid;
				margin: 0 auto;
				display: flex;
			    flex-wrap: wrap;
				
			}
			.wrapper .box{
				width: 100%;
				height: 150px;
				background-color: dimgray;
				display: flex;
				justify-content: space-around;
				
			}
			#import{
				width: 600px;
				height: 100px;
			}
			.wrapper div:nth-of-type(2){
				width: 100%;
				height: 500px;
				background-color: green;
				display: flex;
				flex-wrap: wrap;
				padding: 20px;
				justify-content: space-around;
			}
			 button{
				display: inline-block;
				width: 200px;
				height: 50px;
				font-weight: 700;
				font-size: 20px;
				
			}
			input{
				font-size: 30px;
			}
		</style>
	</head>
	<body>
		<div class="wrapper">
			<div class="box">
				<input id="import" type="text">
			</div>
			<div>
				<button  onclick="cal('1')">1</button>
				<button  onclick="cal('2')">2</button>
				<button  onclick="cal('3')">3</button>
				<button  onclick="cal('4')">4</button>
				<button  onclick="cal('5')">5</button>
				<button  onclick="cal('6')">6</button>
				<button  onclick="cal('7')">7</button>
				<button  onclick="cal('8')">8</button>				
				<button  onclick="cal('+')">+</button>
				<button  onclick="cal('-')">-</button>
				<button  onclick="cal('*')">*</button>
				<button  onclick="cal('/')">/</button>
				<button  onclick="res('=')">=</button>
				<button  onclick="nul('AC')">AC</button>
				
			</div>
		</div>
		<script>
		    var _import=document.getElementById("import"); //获取import
			var b=0;
			function cal(num){
				b=num;
				_import.value+=b;
			}
			function res(){
				_import.value=eval(_import.value);    //将字符串以js代码输出
			}
			function nul(){
				_import.value=null; //清除
			}
		</script>
	</body>
</html>

效果图:

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值