1.代码部分
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>3-6</title>
<style type="text/css">
#div1{
text-align: center;
background-color: black;
border-radius: 15px;
width: 420px;
height: 490px;
}
input[type =button]{
border-radius: 5px;
width: 90px;
height: 50px;
font-size: 30px;
}
#in1{
width: 372px;
height: 80px;
margin-top: 40px;
border-radius: 10px;
font-size: 30px;
text-align: right;
}
</style>
<script>
function calculate(m){
var num = document.getElementById("in1");
switch(m){
case "=":
num.value = eval(num.value);
break;
case "AC":
num.value = "";
break;
case "+/-":
num.value = (-(num.value));
break;
case "ESC":
if(num.value.length > 0){
num.value = num.value.substr(0,num.value.length-1);
}
break;
case "%":
num.value = num.value/100;
break;
default:
num.value =num.value+ m;
break;
}
}
</script>
</head>
<body>
<div id="div1">
<p>
<input type="text" id="in1"/><br/>
</p>
<p>
<input type="button" value="AC" onclick="calculate(this.value)"/>
<input type="button" value="ESC" onclick="calculate(this.value)"/>
<input type="button" value="+/-" onclick="calculate(this.value)"/>
<input type="button" value="/" onclick="calculate(this.value)"/>
</p>
<p>
<input type="button" value="7" onclick="calculate(this.value)"/>
<input type="button" value="8" onclick="calculate(this.value)"/>
<input type="button" value="9" onclick="calculate(this.value)"/>
<input type="button" value="*" onclick="calculate(this.value)"/>
</p>
<p>
<input type="button" value="4" onclick="calculate(this.value)"/>
<input type="button" value="5" onclick="calculate(this.value)"/>
<input type="button" value="6" onclick="calculate(this.value)"/>
<input type="button" value="-" onclick="calculate(this.value)"/>
</p>
<p>
<input type="button" value="1" onclick="calculate(this.value)"/>
<input type="button" value="2" onclick="calculate(this.value)"/>
<input type="button" value="3" onclick="calculate(this.value)"/>
<input type="button" value="+" onclick="calculate(this.value)"/>
</p>
<p>
<input type="button" value="%" onclick="calculate(this.value)"/>
<input type="button" value="0" onclick="calculate(this.value)"/>
<input type="button" value="." onclick="calculate(this.value)"/>
<input type="button" value="=" onclick="calculate(this.value)"/>
</p>
</div>
</body>
</html>
2.效果图
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/29a1da62f7ef22b8ce2582a3faed925d.png)