<script>
var num = 0; // 定义第一个输入的数据
function jsq(num) {
//获取当前输入
if(num=="%"){
document.getElementById('screenName').value=Math.round(document.getElementById('screenName').value)/100;
}else{
document.getElementById('screenName').value += document.getElementById(num).value;
}
}
function eva() {
//计算输入结果
document.getElementById("screenName").value = eval(document.getElementById("screenName").value);
}
function clearNum() {
//清0
document.getElementById("screenName").value = null;
document.getElementById("screenName").focus();
}
function tuiGe() {
//退格
var arr = document.getElementById("screenName");
arr.value = arr.value.substring(0, arr.value.length - 1);
}
</script>
<body>
<center>
<div id="calculator">
<div id="shuRu">
<div>
<input type="text" id="screenName" name="screenName" style="width:233;">
</div>
</div>
<div id="keys">
<div>
<input type="button" id="7" οnclick="jsq(this.id)" value="7" style="width:40;">
<input type="button" id="8" οnclick="jsq(this.id)" value="8" style="width:40;">
<input type="button" id="9" οnclick="jsq(this.id)" value="9" style="width:40;">
<input type="button" id="Back" οnclick="tuiGe()" value="Back" style="width:40;">
<input type="button" id="C" οnclick="clearNum()" value="C" style="width:40;">
</div>
<div>
<input type="button" id="4" οnclick="jsq(this.id)" value="4" style="width:40;">
<input type="button" id="5" οnclick="jsq(this.id)" value="5" style="width:40;">
<input type="button" id="6" οnclick="jsq(this.id)" value="6" style="width:40;">
<input type="button" id="*" οnclick="jsq(this.id)" value="*" style="width:40;">
<input type="button" id="/" οnclick="jsq(this.id)" value="/" style="width:40;">
</div>
<div>
<input type="button" id="1" οnclick="jsq(this.id)" value="1" style="width:40;">
<input type="button" id="2" οnclick="jsq(this.id)" value="2" style="width:40;">
<input type="button" id="3" οnclick="jsq(this.id)" value="3" style="width:40;">
<input type="button" id="+" οnclick="jsq(this.id)" value="+" style="width:40;">
<input type="button" id="-" οnclick="jsq(this.id)" value="-" style="width:40;">
</div>
<div>
<input type="button" id="0" οnclick="jsq(this.id)" value="0" style="width:40;">
<input type="button" id="00" οnclick="jsq(this.id)" value="00" style="width:40;">
<input type="button" id="." οnclick="jsq(this.id)" value="." style="width:40;">
<input type="button" id="%" οnclick="jsq(this.id)" value="%" style="width:40;">
<input type="button" id="eva" οnclick="eva()" value="=" class="buttons" style="width:40;">
</div>
</div>
</div>
</center>
</body>