js之简易计算器
.gif)

<!DOCTYPE html PUBLIC "-//W3C//Dli XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/Dli/xhtml1-transitional.dli">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>简易计算器</title>
<style type="text/css" /> * { padding: 0; margin: 0; }
li { list-style: none; }
body { background: #940032; } #counter { width: 500px; height: 420px; background:#939; margin: 50px auto 0; position: relative; }
#counter h2 { line-height: 42px; padding-left: 15px; font-size: 14px; font-family: arial; color: #ff3333; }
#counter a { font-weight: normal; text-decoration: none; color: #ff3333; }
#counter a:hover { text-decoration: underline; }
#bg { width: 280px; height: 200px; border: 3px solid #680023; background: #990033; filter: alpha(opacity=80); opacity: 0.8; position: absolute; left: 50%; top: 115px; margin-left: -141px; }
#counter_content { width: 250px; position: absolute; top: 130px; left: 130px; z-index: 1; }
#counter_content h3 { margin-bottom: 10px; }
#counter_content h3 input { border: none; width: 223px; height: 30px; line-height: 30px; padding: 0 10px; background: url(images/ico.png) no-repeat; text-align: right; color: #333; font-size: 14px; font-weight: bold; }
#counter_content div { width: 250px; }
#counter_content input { width: 60px; height: 30px; line-height: 30px; float: left; background: url(images/ico.png) no-repeat -303px 0; text-align: center; color: #fff; cursor: pointer; margin: 0 1px 4px 0; border:0; }
#counter_content div > input:hover { background: url(images/ico.png) no-repeat -243px 0; }
#counter p { width: 500px; position: absolute; bottom: 20px; left: 0; color: #ff3333; text-align: center; font-size: 12px; }
</style>
</head>
</head> <body> <div id="counter">
<h2>简易计算</h2>
<div id="counter_content">
<h3><input id="input1" type="text" value="0" /></h3>
<div id="div1">
<input type="button" value="7" onclick="kick('7')"/>
<input type="button" value="8" onclick="kick('8')"/>
<input type="button" value="9" onclick="kick('9')"/>
<input type="button" value="+" onclick="kick('+')"/>
<input type="button" value="4" onclick="kick('4')"/>
<input type="button" value="5" onclick="kick('5')"/>
<input type="button" value="6" onclick="kick('6')"/>
<input type="button" value="-" onclick="kick('-')"/>
<input type="button" value="1" onclick="kick('1')"/>
<input type="button" value="2" onclick="kick('2')"/>
<input type="button" value="3" onclick="kick('3')"/>
<input type="button" value="*" onclick="kick('*')"/>
<input type="button" value="0" onclick="kick('0')"/>
<input type="button" value="C" onclick="kick('C')"/>
<input type="button" value="=" onclick="kick('=')"/>
<input type="button" value="/" onclick="kick('/')"/>
</div>
</div> </div>
</body>
<script type="text/javascript">
var oInput = document.getElementById("input1"); var opt = ""; //预存操作符
var sNum1 = ""; //预存第一个数字
var isAppend = true; //是否要追加数字 function kick(btn){
switch(btn) {
case "=":
oInput.value = cal(sNum1 , oInput.value, opt);
break;
case "+":
case "-":
case "*":
case "/":
oInput.value = cal(sNum1 , oInput.value, opt);
opt = btn;
isAppend = false;
sNum1 = oInput.value
break;
case "C":
opt = "";
sNum1 = "";
oInput.value = "0";
break;
default:
oInput.value = oInput.value == "0" ? "" : oInput.value;
if(opt == "" || isAppend) {
oInput.value += btn;
} else {
oInput.value = btn;
isAppend = true;
} }
} function cal(num1 , num2 , opt){
switch(opt) {
case "+" : return Number(num1)+Number(num2);
case "-" : return Number(num1)-Number(num2);
case "*" : return Number(num1)*Number(num2);
case "/" : return Number(num1)/Number(num2);
default: return Number(oInput.value);
}
}
</script>
</html>
js之简易计算器的更多相关文章
- 使用html+css+js实现简易计算器
使用html+css+js实现简易计算器, 效果图如下: html代码如下: <!DOCTYPE html> <html lang="en"> <he ...
- 项目:JS实现简易计算器案例
组件化网页开发下的: 步骤一:让页面动起来的JavaScript深入讲解 的 项目:JS实现简易计算器案例
- 用js制作简易计算器及猜随机数字游戏
<!doctype html><html><head> <meta charset="utf-8"> <title>JS ...
- 原生JS实现简易计算器
<!doctype html> <html> <head> <meta charset="utf-8"> <title> ...
- JS编写简易计算器
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/html"> <head lang=" ...
- JS实现简易计算器的7种方法
先放图(好吧比较挫) 方法一:最容易版 <!DOCTYPE html> <html lang="zh-CN"> <head> <meta ...
- html、css、js实现简易计算器
学习HTML,CSS,JS一个月后,想着能自己是否能写出一个简单的东西,故编写了简易的计算器,之前也写过一个坦克大战,坦克大战的有些基本功能没有实现, 故也没有记录下来,想来,对这行初来咋到的,还是需 ...
- JS简易计算器的实现,以及代码的优化
用JS实现简易计算器 首先创建结构和样式 <!DOCTYPE html> <html lang="en"> <head> <meta ch ...
- 【实践】js实现简易的四则运算计算器
最近看了一个大神推荐的某公司面试程序员的js 面试题,题目是用js 做一个计算器于是跟着大神的思想自己做了一下 ps:功能还没有完善好毕竟自己还是一只菜鸟还在不断学习中. 闲话不多说先上css代码 & ...
随机推荐
- django中的分页设置
1.在控制台中的展示 from django.core.paginator import Paginator iter = 'abcdefghijklmn' inator = Paginator(it ...
- docker 修改 mysql 5.7 sql_mode
docker exec -ti {容器ID} /bin/bash 进入容器 apt-get install vim 安装vim 找到 vim /etc/mysql/my.cnf 在 [mysqld ...
- random模块中最常用的几个函数
转自:http://www.cnblogs.com/yd1227/archive/2011/03/18/1988015.html 随机整数:>>> import random> ...
- 【Semantic Segmentation】 Instance-sensitive Fully Convolutional Networks论文解析(转)
这篇文章比较简单,但还是不想写overview,转自: https://blog.csdn.net/zimenglan_sysu/article/details/52451098 另外,读这篇pape ...
- 【网络结构】GoogLeNet inception-v1:Going deeper with convolutions论文笔记
目录 0. 论文链接 1. 概述 2. inception 3. GoogleNet 参考链接 @ 0. 论文链接 1. 概述 GoogLeNet是谷歌团队提出的一种大体保持计算资源不变的前提下, ...
- JVM 内存调优 与 实际案例
堆内存设置 原理 JVM堆内存分为2块:Permanent Space 和 Heap Space. Permanent 即 持久代(Permanent Generation),主要存放的是Java类定 ...
- Codeforces Round #414 C. Naming Company
http://codeforces.com/contest/794/problem/C 题意: 有两个人要为公司起名字,每个人手中都有n个字符,现在要取一个n个字符长度的公司名.两人轮流取名,每次选择 ...
- 数据库原理及应用-SQL数据操纵语言(Data Manipulation Language)和嵌入式SQL&存储过程
2018-02-19 18:03:54 一.数据操纵语言(Data Manipulation Language) 数据操纵语言是指插入,删除和更新语言. 二.视图(View) 数据库三级模式,两级映射 ...
- php特级课---4、网站服务监控
php特级课---4.网站服务监控 一.总结 一句话总结:这些是架构师的知识 网络流量监控:cacti,mrtg 邮件报警系统:postfix 压力测试工具:Apache压力测试软件-ab,Mysql ...
- ubuntu 安装包过程中遇到的一个错误解决办法
错误提示如下: 将会安装下列额外的软件包: libdigest-hmac-perl libqt5test5下列[新]软件包将被安装: libdigest-hmac-perl下列软件包将被升级: lib ...