用JS写的简单的计算器实现代码
1.本页效果图片
2.美化后的效果
Array.prototype.remove=function(index)
{
if(isNaN(index)||index>this.length){return false;}
for(var i=0,n=0;i 0){
del = 1;
this.tmp = this.register[0];
}
if(_sign == '-'){
this.tmp = -this.tmp;
}else{
this.tmp = Math.abs(this.tmp);
}
this.output.value = this.tmp;
if(del == 1){
this.register[0] = this.tmp;
this.tmp = '';
}
}
//获取按键
this.getValue = function(input){
var _in = input;
var inputList = document.getElementsByTagName("input");
this.output = inputList[0];
regMethod = /^[\+|\-|\*|\/]$/i;
if(regMethod.test(_in)){
this.setMethod(_in);
return;
}
regNum = /^\d$/i;
if(regNum.test(_in)){
this.setValue(_in);
return;
}
regSign = /^\+\/\-$/i;
if(regSign.test(_in)){
this.setSign(_in);
return;
}
regResult = /^=$/;
if(regResult.test(_in)){
this.run();
return;
}
}
//计算结果
this.run = function(type){
if(this.register.length
#main{
width:100%;
height:100%;
}
#inputs{
position:relative;
top:50%;
left:50%;
}
.inbutton{
width:30px;
}
.outbutton{
width:145px;
text-align:right;
}
.tcenter{
text-align:center;
}
etongchina@gmail.com
[Ctrl+A 全选 注:如需引入外部Js需刷新才能执行]