计算机计算公式代码,简单的计算器代码
简单的计算器代码
作为初学者能写出⼀个简单的程序再开⼼不过了。下⾯⼩编给⼤家介绍⼀个简单的计算器代码程序。
#box{width: 295px; margin: 0 auto; text-align: justify; border: 1px solid #ddd; padding: 15px;}
.d_num{display: inline-block; margin:  10px; width: 33px; height: 30px; border: 1px solid #ddd; text-align: center; line-height: 30px; cursor: pointer;}
.sum{margin: 0 10px 10px; line-height: 30px; font-size: 20px;}
#sum{width: 205px; height: 30px; padding: 0 5px; margin-left: 5px; font-size: 20px;}
#process{width: 255px; height: 30px; padding: 0 5px; margin-left: 5px; font-size: 20px;}
SUM:
1 2 3 <- C
4 5 6 * /
7 8 9 + -
0 00 . % =
var $box = ElementById('box');
var $sum = ElementById('sum');
var $process = ElementById('process');
var sum = 0, process = '', num1 = '', num2 = '', temp = '', statu = false;
$lick = function(e){
var event = window.event || e;
var ele = event.srcElement || event.target;
var _className = ele.className;
if(_className == 'd_num'){
var num = Attribute('data-num');//点击的.按钮对应的值
var NotNum = isNaN(num);
if(!NotNum || num == '.'){ //点击了数字
javascript计算器代码
if(!statu){ //还没点击过符号
if(num1 == '0'){
num1 = '';
}
num1 += num;
process = num1;
}else{ //已经点击过符号
if(num2 == '0'){
num2 = '';
}
num2 += num;
process = num1 + temp + num2; }
$process.value = process;
}
else{ //点击了符号
if(num1 == ''){//⾮法操作
return false;
}
if(num == 'C'){//归零
num1 = '';
num2 = '';
process = '';
temp = '';
sum = '';
$process.value = '0';
$sum.value = '0';
更多相关⽂章推荐:

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。