该部分计算器设置借鉴于网络 本人对部分代码进行修改优化 仅供参考
function $(id){return document.getElementById(id);}
var str;
var dengyu;
function init(){
str = document.getElementById("text");
str.value=0;
str.disabled="disabled";
}
function isNull(n){
if(n=='0'||n.length==0){
return true;
}else {
return false;
}
}
function display(n) //显示到文本框
{
str = document.getElementById("text");
if (isNull(str.value)) {
str.value=n;
}else{
str.value = str.value + n;
}
}
function equals() //等于
{
str = document.getElementById("text");
dengyu = eval(str.value);//Eval 函数计算表达式,并返回结果。参数expression必须需要能够计算的表达式
str.value = dengyu;//此函数将在VBScript内学习 方式借鉴于网络素材
}
function back() //退格
{
str = document.getElementById("text");
str.value = str.value.substr(0,str.value.length-1);
if (isNull(str.value)) {
str.value=0
}
return str.value;
}
function reset() //清除
{
str = document.getElementById("text");
str.value = 0;
}