20161116简单的计算器_第1页
20161116简单的计算器_第2页
20161116简单的计算器_第3页
20161116简单的计算器_第4页
20161116简单的计算器_第5页
已阅读5页,还剩3页未读, 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、简单的计算器,Javascript代码,var num=0,result=0,numshow=0; var operate=0; /判断输入状态的标志 var calcul=0; /判断计算状态的标志 var quit=0; /防止重复按键的标志 function command(num) var str=String(document.calculator.numScreen.value); /获得当前显示数据 str=(str!=0) ? (operate=0) ? str : ) : ; /如果当前值不是0,且状态为0,则返回当前值,否则返回空值; str=str + String(nu

2、m); /给当前值追加字符 document.calculator.numScreen.value=str; /刷新显示 operate=0; /重置输入状态 quit=0; /重置防止重复按键的标志 function dzero() var str=String(document.calculator.numScreen.value); str=(str!=0) ? (operate=0) ? str + 00 : 0) : 0; /如果当前值不是0,且状态为0,则返回当str+00,否则返回0; document.calculator.numScreen.value=str; operat

3、e=0; function dot() var str=String(document.calculator.numScreen.value); str=(str!=0) ? (operate=0) ? str : 0) : 0; /如果当前值不是0,且状态为0,则返回当前值,否则返回0; for(i=0; i=str.length;i+) /判断是否已经有一个点号 if(str.substr(i,1)=.) return false; /如果有则不再插入 str=str + .; document.calculator.numScreen.value=str; operate=0; func

4、tion del() /退格 var str=String(document.calculator.numScreen.value); str=(str!=0) ? str : ; str=str.substr(0,str.length-1); str=(str!=) ? str : 0; document.calculator.numScreen.value=str; function clearscreen() /清除数据 num=0; result=0; numshow=0; document.calculator.numScreen.value=0; function plus() /

5、加法 calculate(); /调用计算函数 operate=1; /更改输入状态 calcul=1; /更改计算状态为加 function minus() /减法 calculate(); operate=1; calcul=2; function times() /乘法 calculate(); operate=1; calcul=3; function divide() /除法 calculate(); operate=1; calcul=4; function persent() /求余 calculate(); operate=1; calcul=5; function equal

6、() calculate(); /等于 operate=1; num=0; result=0; numshow=0; / function calculate() numshow=Number(document.calculator.numScreen.value); if(num!=0 ,Html代码, 写给新手:js表单操作(四) 简单计算器(二) body font-size:12px; font-family:Arial, Georgia, Times New Roman, Times, serif; color:#555; text-align:center; background-

7、color:#e2e2e2; h6 margin:0; font-size:12px; #calculator width:240px; height:auto; overflow:hidden; margin:10px auto; border:#fff 1px solid; padding-bottom:10px; background-color:#f2f2f2; #calculator div clear:both; #calculator ul padding:0; margin:5px 14px; border:#fff 1px solid; height:auto; overfl

8、ow:hidden #calculator li list-style:none; float:left; width:32px; height:32px; margin:5px; display:inline; line-height:32px; font-size:14px; background-color:#eaeaea; #calculator li.tool background-color:#e2e2e2; #calculator li:hover background-color:#f9f9f9; cursor:pointer; #calculator li:active ba

9、ckground-color:#fc0; cursor:pointer; #calculator li.tool:active background-color:#d8e8ff; cursor:pointer; #calcu-head text-align:left; padding:10px 15px 5px; span.imyeah float:right; color:#ccc; span.imyeah a color:#ccc; .screen width:200px; height:24px; line-height:24px; padding:4px; border:#e6e6e6

10、 1px solid; border-bottom:#f2f2f2 1px solid; border-right:#f2f2f2 1px solid; margin:10px auto; direction:ltr; text-align:right; font-size:16px; color:#999; #calcu-foot text-align:left; padding:10px 15px 5px; height:auto; overflow:hidden; span#note float:left; width:210px; height:auto; overflow:hidde

11、n; color:red; span.welcome clear:both; color:#999; span.welcome a float:right; color:#999; /此处插入上面的js代码 Im Yeah!简单的计算器 7 8 9 C 4 5 6 1 2 3 + - 0 00 . % = 欢迎使用javascript计算器!反馈 ,HTML, 简单的计算器 walker 欢迎使用JavaScript计算器 反馈 ,CSS, /*Basic reset*/ * margin:0; padding:0; box-sizing: border-box; font: 14px Ari

12、al,sans-serif; html height:100%; background-color:lightslategrey; #calculator margin: 15px auto; width:330px; height:400px; border: 1px solid lightgray; background-color:darkgrey; padding:15px; /*LOGO*/ .LOGO height:20px; .LOGO .name float:left; line-height:30px; .LOGO .verson float:right; line-heig

13、ht:30px; /*screen*/ #shuRu margin-top:15px; .screen margin-top:5px; width:300px; height:40px; text-align: right; padding-right:10px; font-size:20px; #keys border:1px solid lightgray; height:223px; margin-top:25px; padding:8px; #keys .last margin-right:0px; .footer margin-top:20px; height:20px; .foot

14、er .link float:right; #keys .buttons float:left; width: 42px; height: 36px; text-align:center; background-color:lightgray; margin: 0 17px 20px 0; ,Javascript, varnum = 0;/ 定义第一个输入的数据 functionjsq(num) /获取当前输入 if(num=%) document.getElementById(screenName).value=Math.round(document.getElementById(screenName).value)/100; else document.getElementById(screenName).value += document.getElementById(num).value; functioneva() /计算输入结果 document.getElementById(screenName).value = eval(document.getElementById(screenName).value); functionc

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论