简单的计算器代码
简单的计算器代码
作为初学者能写出一个简单的程序再开心不过了。下面小编给大家介绍一个简单的计算器代码程序。
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title></title>
<style type="text/css">
#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;}</style>
<p id="box">
<p class="sum">
<input id="process" name="process" type="text" value="0" /></p>
<p class="sum">
SUM:<input id="sum" name="sum" type="text" value="0" /></p>
<p>
<span class="d_num" data-num="1">1</span> <span class="d_num" data-num="2">2</span> <span class="d_num" data-num="3">3</span> <span class="d_num" data-num="<-"><-</span> <span class="d_num" data-num="C">C</span></p>
<p>
<span class="d_num" data-num="4">4</span> <span class="d_num" data-num="5">5</span> <span class="d_num" data-num="6">6</span> <span class="d_num" data-num="*">*</span> <span class="d_num" data-num="/">/</span></p>
<p>
<span class="d_num" data-num="7">7</span> <span class="d_num" data-num="8">8</span> <span class="d_num" data-num="9">9</span> <span class="d_num" data-num="+">+</span> <span class="d_num" data-num="-">-</span></p>
<p>
<span class="d_num" data-num="0">0</span> <span class="d_num" data-num="00">00</span> <span class="d_num" data-num=".">.</span> <span class="d_num" data-num="%">%</span> <span class="d_num" data-num="=">=</span></p>
</p>
<script type="text/javascript">
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 = windoevent || e;
var ele = Element || get;
var _className = ssName;
if(_className == 'd_num'){
var num = Attribute('data-num');//点击的按钮对应的.值
var NotNum = isNaN(num);
if(!NotNum || num == '.'){ //点击了数字
if(!statu){ //还没点击过符号
if(num1 == '0'){
num1 = '';
}
num1 += num;
process = num1;
}else{ //已经点击过符号
if(num2 == '0'){
num2 = '';
}
num2 += num;
process = num1 + temp + num2;
}
$ue = process;
}
else{ //点击了符号
if(num1 == ''){//非法操作
return false;
}
if(num == 'C'){//归零
num1 = '';
num2 = '';
process = '';
temp = '';
sum = '';
$ue = '0';
$ue = '0';
更多相关文章推荐:
1.简单的计算器代码
2.纯css实现蓝色圆角效果水平导航菜单代码
3.如何使用Google-Code-Prettify 实现代码高亮功能
如何实现中英文双语菜单效果代码
5.C语言中字符串和数字的相互转换实现代码分析
6.宽带连接出现651错误代码怎么办
生成缩略图的两种方法(代码)
a开发代码性能优化是什么
aScript简单实现放大镜效果代码
生成图片缩略图类示例代码
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 1156092664@qq.com 举报,一经查实,本站将立刻删除。