jquery计算器(改良版)
代码:
<!Doctype html>
<html>
<meta charset="UTF-8">
<title>计算器</title>
<script src="jquery.min.js"></script>
<style>
button{ width:80px;
height:50px;
background-color:#969696;
color:white;
font-size:17px;
}
</style>
<body>
<table>
<tr>
<td colspan="4" style="text-align:center;">
<input type="text" value="0" style="font-size:17px;text-align:right;width:330px;height:50px;">
</td>
</tr>
<tr>
<td>
<button class="num">7</button>
</td>
<td>
<button class="num">8</button>
</td>
<td>
<button class="num">9</button>
</td>
<td>
<button class="operator">+</button>
</td>
</tr>
<tr>
<td>
<button class="num">4</button>
</td>
<td>
<button class="num">5</button>
</td>
<td>
<button class="num">6</button>
</td>
<td>
<button class="operator">-</button>
</td>
</tr>
<tr>
<td>
<button class="num">1</button>
</td>
<td>
<button class="num">2</button>
</td>
<td>
<button class="num">3</button>
</td>
<td>
<button class="operator">*</button>
</td>
</tr>
<tr>
<td>
<button class="num">0</button>
</td>
<td>
<button id="point">.</button>
</td>
<td>
<button id="eq">=</button>
</td>
<td>
<button class="operator">/</button>
</td>
</tr>
<tr>
<td>
<button id="clean">C</button>
</td>
</tr>
</table>
</body>
</html>
<script>
var status = 0;
var operat;
var firstnum;
var secondnum;
$("#clean").click(function(){
status = 0;
$("input").val(0);
firstnum = 0;
secondnum = 0;
})
$(".num").click(function(){
if(status == 0){
if($("input").val()==='0'){
$("input").val($(this).html());
}else if($("input").val() == '0.'){
$("input").val('0.' + $(this).html());
}else{
$("input").val($("input").val() + $(this).html());
}
firstnum = $("input").val();
}else{
if($("input").val() == '0.'){
$("input").val('0.' + $(this).html());
secondnum = $("input").val();
}else{
$("input").val($(this).html());
secondnum = $("input").val();
}
}
})
$(".operator").click(function(){
status = 1;
operat = $(this).html();
})
$("#point").click(function(){ $("input").val($("input").val() + $(this).html());
})
$("#eq").click(function(){ if(operat == '+'){
$("input").val((parseFloat(firstnum)*10+parseFloat(secondnum)*10)/10);
}else if(operat == '-'){
$("input").val((parseFloat(firstnum)*10-parseFloat(secondnum)*10)/10);
}else if(operat == '*'){
$("input").val((parseFloat(firstnum)*10*parseFloat(secondnum)*10)/100);
}else{
$("input").val((parseFloat(firstnum)*10/parseFloat(secondnum)*10)/100);
}
firstnum = $("input").val();
status = 0;
})
</script>
效果图:
jquery计算器(改良版)的更多相关文章
- 一句代码美化你的下框之jquery.selectMM修复版(jquery.selectMM v0.9 beta 20141217)
一句代码美化你的下框之jquery.selectMM修复版(jquery.selectMM v0.9 beta 20141217) 浏览效果: http://www.beyond630.com/jqu ...
- jQuery Mobile (整合版)
jQuery Mobile (整合版) 前言 为了方便大家看的方便,我这里将这几天的东西整合一下发出. 里面的例子请使用手机浏览器查看. 什么是jQuery Mobile? jquery mobile ...
- office全系列激活脚本-改良版
@ECHO OFFTITLE office 全版本系统激活@echo offfor /l %%a in (8,1,16) do (for /f "tokens=*" %%i in ...
- windows全系列激活脚本-改良版.cmd
@ECHO OFFTITLE Windows 全版本系统激活cscript //nologo %Systemroot%\system32\slmgr.vbs -skms 10.1.1.12ECHO 检 ...
- office全系列激活脚本-改良版.cmd
@ECHO OFFTITLE office 全版本系统激活@echo offfor /l %%a in (8,1,16) do (for /f "tokens=*" %%i in ...
- 锋利的jQuery(第二版)学习总结
通过对<锋利的jQuery>(第二版)一书的学习,发现此书讲解通俗易懂,是学习jQuery的一本很好的指导书,特作如下总结. 此书主要讲解了jQuery的常用操作,包括认识jQuery,j ...
- 优化改良版:数组,List,等集合需要加逗号或其它符合转成字符串
大家经常需要数组加逗号拼接成字符串的情况传统作法就是写for,foreach拼接, 现给出优化改良版数组,List,等集合需要加逗号或其它符合转成字符串方法: List<string> l ...
- Python实例---利用正则实现计算器[FTL版]
import re # 格式化 def format_str(str): str = str.replace('--', '+') str = str.replace('-+', '-') str = ...
- 闲来无事写一个jquery计算器,没有进行封装......
<!doctype html> <html> <head> <meta charset="utf-8" /> <title&g ...
随机推荐
- gem install ruby-odbc失败
解决: brew install unixodbc gem install ruby-odbc -v '0.99998'
- C语言中malloc函数的理解
在C语言中malloc函数主要是用在堆内存的申请上,使用malloc函数时,函数会返回一个void *类型的值,这个值就是你申请的堆内存的首地址:为什么返回的地址是一个void *类型的地址呢?首先我 ...
- linux 下安装 Cisco Packet Tracer 7.11以及一些注意
https://blog.csdn.net/qq_35882901/article/details/77652571 https://linux.cn/article-5576-1.html 开启登录 ...
- Shuffling Machine
7-43 Shuffling Machine(20 分) Shuffling is a procedure used to randomize a deck of playing cards. Bec ...
- Verilog_Day3
内容为书中第5章 条件语句 条件语句必须在过程块语句中使用.所谓过程块语句是指由 initial 和 always 语句引导的执行语句集合.除这两种块语句引导的begin_end块中可以编写条件语句外 ...
- 为什么我要放弃javaScript数据结构与算法(第五章)—— 链表
这一章你将会学会如何实现和使用链表这种动态的数据结构,这意味着我们可以从中任意添加或移除项,它会按需进行扩张. 本章内容 链表数据结构 向链表添加元素 从链表移除元素 使用 LinkedList 类 ...
- C#使用API屏蔽系统热键和任务管理器
最近做的一个winform类型的项目中需要屏蔽系统热键,在网上搜索了一下,基本上都是调用api来进行hook操作,下面的代码就可以完成功能 using System; using System.IO; ...
- 创龙DSP6748开发板上电测试-第一篇
1. 创龙DSP6748开发板测试.2980元的售价很高,我估计新的1200元比较合适,当然创龙定价是按照供需关系的.仿真器XDS100V2卖598元,真是狮子大张口. 2. 上电是5V-2A的电源. ...
- Java: Replace a string from multiple replaced strings to multiple substitutes
Provide helper methods to replace a string from multiple replaced strings to multiple substitutes im ...
- JVM监控远程服务器
1. 首先配置服务器端,进入服务器tomcat的bin目录下,打开catalina.sh配置文件,xxx为服务器配置路径. # cd /xxx/apache-tomcat-/bin # vim cat ...