本文运用前端代码实现一个简单的计算器界面,并通过JS实现了基本的运算功能。(加、减、乘、除、清屏/退格、取余、取倒)
1.编写前端界面
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>我的计算器</title>
<style>
.containor{
border:1px solid black;
background-color: #fafafa;
height: 380px;
width: 296px;
margin: auto;
margin-top: 40px;
}
.top{
background-color: lightgray;
height: 30px;
}
a{
display: block;
float: left;
font-size: 8px;
height: 26px;
padding: 0 6px;
margin-left: 6px;
line-height: 26px;
}
a:hover{
background-color: dimgray;
color: white;
cursor: default;
}
.input{
width: 86%;
height:60px;
padding: 4px;
margin: 0 auto;
margin-top: 12px;
}
.input:focus{
outline: none;
}
button{
width: 50px;
height: 30px;
margin: 2px;
text-align: center;
font-size: 10px;
border: 0.5px solid gray;
}
button:hover{
border: 1px solid gray;
background-color: #ffaa55;
outline: none;
}
.bottom{
width: 100%;
height: 30px;
background-color:lightgray;
color: white;
position: relative;
margin-top: 5