【趣味编程】科学计算器代码个人作品!

纯自己手工完成基本样式!各种计算功能! 一些动画参考w3c

[趣味编程] 科学计算器代码!个人作品!

注释:背景用的别人的不是自己写的!

自己在编程界还是个小学生希望大佬能够指点一二!

把js代码放上!请大佬指点!

/*全局 变量  出结果后 清空在输入*/
var zhi1 = "";
var zhi2 = "";
var chujieguohou = false;
/*数字的输入*/
function shuzi(number){
/*判断 等号点了 后要清空*/
if(chujieguohou == true){
document.getElementById('shu').value = "";
/*在次改 赋值*/
chujieguohou = false;
}
var shujie=document.getElementById('shu').value;
if(shujie.length<=20){
document.getElementById('shu').value +=number;
}

}
/*计算结果这是js给的 eval*/
function dengyu(){

/*赋值给等号*/
/**/
var shujie = document.getElementById("shu").value;
var lastCode = shujie.charCodeAt(shujie.length-1);
/*判断 是否 要等于清空 最后一位如果是 符号则等于 不清空 不计算 不是则计算 并赋值*/
if(!(lastCode == 37 ||lastCode == 47 ||lastCode == 42 ||lastCode == 43 ||lastCode == 45 ||lastCode == 46)){
chujieguohou = true;
}

var shujie=document.getElementById('shu').value;
var shu = eval(shujie);
var changdu = eval(shujie) + "" ;
if(changdu.length <= 9){
document.getElementById('shu').value = shu;
}
else{
var si=shu.toFixed(4);
document.getElementById('shu').value = si;
}
return shu;
}




/*存*/
function chucucn(){

var jieguo = dengyu;
qudezhi = jieguo() ;
zhi1 = jieguo();

}
/*取*/
function quchu(){
document.getElementById('shu').value = qudezhi;

}

/*清空*/
function qingkong(){
qudezhi = '0';
}

/*累存*/
function leicun(){
var jieguo2 = dengyu;
zhi2 = jieguo2() ;
qudezhi = zhi1+zhi2;

}

/*积存*/
function jicun(){
var jieguo3 = dengyu;
zhi3 = jieguo3();
qudezhi = zhi1 * zhi3;
}


//清零
function qingchu(){
var shu=document.getElementById("shu");
shu.value="";
document.getElementById("shu").focus();
}
//退格
function tuige(){
var tt=document.getElementById("shu");
tt.value=tt.value.substring(0,tt.value.length-1);
}
//正负号
function zhengfuhao(){
var zhf=document.getElementById("shu").value;
if(zhf.charCodeAt(0)==45){
document.getElementById("shu").value = zhf.substr(1, zhf.length);
}
else{
document.getElementById("shu").value = "-" +zhf;
}

}
/*防止重复符号 */
/*方案:判断最后一个是否 为符号 是则不输入 不是则输入*/
/*并防止第一位为符号*/
/*&&(逻辑与)、||(逻辑或)、!(逻辑非)。*/
function chongfufuhao(number){
var shujie = document.getElementById("shu").value;
var lastCode = shujie.charCodeAt(shujie.length-1);
if(!(lastCode == 37 ||lastCode == 47 ||lastCode == 42 ||lastCode == 43 ||lastCode == 45 ||lastCode == 46) && ( lastCode == 48 || lastCode == 49 || lastCode == 50 || lastCode == 51 || lastCode == 52 || lastCode == 53 || lastCode == 54 || lastCode == 55 || lastCode == 56 || lastCode == 57 )) {
document.getElementById("shu").value += number;
}
}

资源下载

上一篇

HTML用JavaScript写简单计算器教程