在开题的间隙,整合两天的碎片时间,写了一个简单计算器的小程序(比较粗糙,还有很多需要改进的地方)
下面呢,就记录一下自己的设计过程:
1. 设计思路
①按键需要显示,结果需要显示,故需要一个显示器,在这里 ,我采用的是input ,对于计算结果,我利用的是强大的eval()函数,它能计算原始字符串的值
②若在计算输入时,按错一个键,可采用delete删除掉;而当需要一次性全部删除显示器中的数值时,采用clear键
③ 每个按键都有语音同步提示
2.设计且已经实现的计算器界面如下图:
3.源码实现
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>compute</title>
<style type="text/css">
form{
position: fixed;
width: 260px;
height: 270px;
background-color:lightgoldenrodyellow;
margin-left: 20px;
border:2px solid black;
}
.result{
position: fixed;
height: 40px;
font-size: 20px;
margin-left: 7px;
margin-top: 10px;
border: 2px solid rosybrown;
}
.content{
margin-left: 15px;
margin-top: 16px;
}
input{
height: 28px;
}
.delete ,.equal ,.clear{
width: 65px;
margin-top: 30px;
}
.delete{
margin-right: 10px;
position: relative;
}
.clear{
margin-left: 2px;
margin-right: 8px;
position: relative;
}
.number , .sign , .point , .percent{
margin-top: 10px;
margin-right: 12px;
width: 42px;
}
.equal{
background-color: red;
}
</style>
</head>
<body>
<form name="compute">
<input type="text" class="result" id="output" maxlength="20" value=""/