啊因为懒得去找素材了,所以做了一个仿win10计算器的灰白色计算器。

参考:http://www.html5tricks.com/jquery-calculator.html

HTML源码:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> <title>Caluculator</title>
<link type="text/css" rel="stylesheet" href="css/reset.css">
<link type="text/css" rel="stylesheet" href="css/main.css">
<script type="text/javascript" src="js/script.js"></script> <meta name="description" content="">
<meta name="keywords" content="">
<link href="" rel="stylesheet">
</head>
<body>
<div id="counter">
<h3>在线计算器</h3>
<input type="text" value="0" id="inputFrame"/>
<ul>
<li>7</li><li>8</li><li>9</li><li class="order">+</li>
<li>4</li><li>5</li><li>6</li><li class="order">-</li>
<li>1</li><li>2</li><li>3</li><li class="order">×</li>
<li>0</li><li>C</li><li>=</li><li class="order">÷</li>
</ul>
</div>
</body>
</html>

JS源码:

window.onload=function(){
var lis=document.getElementsByTagName("li");
for(var i=0;i<lis.length;i++){
lis[i].onmousedown=doInput;
lis[i].onmouseover=function(){
this.className="active";
}
lis[i].onmouseout=function(){
this.className="";
}
}
} var refresh=false;
var sum='0';
var preOrder=''; function cal(a,b,order){
var res=0;
if(order=='+'){
res=a+b;
}
else if(order=='-'){
res=a-b;
}
else if(order=='×'){
res=a*b;
}
else if(order=='÷'){
res=a/b;
}
else{
res=b;
}
return res;
} function doInput(){
var oInput=document.getElementById("inputFrame");
var iHTML=this.innerHTML; if(iHTML=='='){
oInput.value=cal(parseInt(sum),parseInt(oInput.value),preOrder);
refresh=true;
sum='0';
preOrder='';
}
else if(iHTML=='+'||iHTML=='-'||iHTML=='×'||iHTML=='÷'){
oInput.value=cal(parseInt(sum),parseInt(oInput.value),preOrder);
refresh=true;
sum=oInput.value;
preOrder=iHTML;
}
else if(iHTML=='C'){
oInput.value='0';
sum='0';
preOrder='';
}
else{
if(refresh){
oInput.value=parseInt(iHTML);
refresh=false;
}
else{
oInput.value=parseInt(oInput.value+iHTML);
}
}
}

CSS源码:

@charset "UTF-8";

/* reset.css */
body,ul,ol,li,p,h1,h2,h3,h4,h5,h6,form,fieldset,table,td,img,div,dl,dt,dd,input{
margin: 0;
padding: 0;
}
body{
font-size: 12px;
}
img{
border: none;
}
li{
list-style: none;
}
input,select,textarea{
outline: none;
border: none;
}
textarea{
resize: none;
}
a{
text-decoration: none;
color: #656565;
}
/* 清除浮动 */
.clearfix:after{
content: "";
display: block;
clear: both;
}
.clearfix{
zoom: 1;
}
/* 设置浮动 */
.fl{
float: left;
}
.fr{
float: right;
} /*************************************************************/ /* main.css */
#counter{
width: 500px;
height: 420px;
margin: 50px auto;
position: relative;
border: #cfcfcf solid 1px;
}
#counter h3{
margin:10px 0 0 10px;
width: 490px;
height: 30px;
font-size: 23px;
/* font-weight: bold; */
}
#counter input{
width: 490px;
height: 99px;
line-height: 99px;
padding-right: 10px;
font-size: 40px;
font-weight: bold;
text-align: right;
border-bottom: #cfcfcf solid 1px;
}
#counter ul{
width: 500px;
height: 280px;
}
#counter li{
float: left;
width: 125px;
height: 70px;
line-height: 70px;
background-color: #e6e6e6;
/* font-weight: bold; */
font-size: 30px;
text-align: center;
}
#counter .active{
background-color: #cfcfcf;
}

PS:以后这个博客应该不会写ACM的东西了,今年寒假和暑假撸了一下前端,算是入了门吧。也想告别过去一年的ACM生涯了,感觉自己的天赋真的不够,甚至努力程度也不够,兴趣过了之后只觉烦躁,而且不想以后的假期都耗在环境恶劣的学校宿舍,所以打算放弃了。打算开始体验一下后端开发!Kadima!

#js#简单的在线计算器的更多相关文章

  1. js加减乘除在线计算器代码

    js加减乘除在线计算器代码 在线演示本地下载

  2. Tourist.js – 简单灵活的操作指南和导航插件

    Tourist.js 是一个基于 Backbone 和 jQuery 开发的轻量库,帮助你在应用程序创建简单易用的操作指南和导航功能.相比网站,它更适合用于复杂的,单页网站类型的应用程序.Touris ...

  3. 原生js简单调用百度翻译API实现的翻译工具

    先来个在线demo: js翻译工具 或者百度搜索js简单调用百度翻译API工具(不过有个小小的界面显示bug,我想细心的人应该会发现) 或者直接前往该网址:js翻译工具 或者前往我的github:gi ...

  4. baguetteBox.js - 简单易用的 lightbox 插件

    baguetteBox.js 是一个简单和易于使用的响应式的图像 Lightbox 插件,支持滑动手势在移动设备上使用.纯 JavaScript 实现,不依赖第三方库和插件,赶紧来体验吧. 在线演示  ...

  5. 基于PHP实现一个简单的在线聊天功能(轮询ajax )

    基于PHP实现一个简单的在线聊天功能(轮询ajax ) 一.总结 1.用的轮询ajax 二.基于PHP实现一个简单的在线聊天功能 一直很想试着做一做这个有意思的功能,感觉复杂的不是数据交互和表结构,麻 ...

  6. pdf.js实现图片在线预览

    项目需求 前段时间项目中遇到了一个模块,是关于在线预览word文档(PDF文件)的,所以,找了很多插件,例如,pdf.js,pdfobject.js框架,但是pdfobject.js框架对于IE浏览器 ...

  7. js简单 图片版时钟,带翻转效果

    js简单 图片版时钟,带翻转效果 <!DOCTYPE html> <html> <head> <meta charset="UTF-8"& ...

  8. js简单操作Cookie

    贴一段js简单操作Cookie的代码: //获取指定名称的cookie的值 function getCookie(objName) { var arrStr = document.cookie.spl ...

  9. js简单弹出层、遮罩层

    <html> <head> <title>js简单弹出层</title> <style> /*阴影边框效果*/ .box-shadow-1 ...

随机推荐

  1. 基于ffmpeg的C++播放器1

    基于ffmpeg的C++播放器 (1) 2011年12月份的时候发了这篇博客 http://blog.csdn.net/qq316293804/article/details/7107049 ,博文最 ...

  2. Changing the working directory of VIM

    Sometimes we want to open another file in the same folder with current editing file, what we can do ...

  3. 竞价广告系统-ZooKeeper介绍

    ZooKeeper介绍 为了讲述的完整性,介绍一下ZooKeeper.ZooKeeper在Index和Ad Server里使用比较多,虽然它可能没有google的Chubby好,但它是开源的工具.举一 ...

  4. 转载-windows下MySql5.6.17没有setup.exe时的安装方法

    转载出处为:http://blog.csdn.net/zgrjkflmkyc/article/details/25321537 (最终,我也没有安装下述的方法安装成功,虽然有服务,但是服务启动不正常, ...

  5. 使用 Spring 2.5 TestContext 测试DAO层

    资源准备:   mysql5.0 spring-2.5  hibernate-3.2  junit-4.jar 创建表 DROP TABLE IF EXISTS `myproject`.`boys`; ...

  6. 读取同一文件夹下多个txt文件中的特定内容并做统计

    读取同一文件夹下多个txt文件中的特定内容并做统计 有网友在问,C#读取同一文件夹下多个txt文件中的特定内容,并把各个文本的数据做统计. 昨晚Insus.NET抽上些少时间,来实现此问题,加强自身的 ...

  7. spring实现数据库读写分离

    现在大型的电子商务系统,在数据库层面大都采用读写分离技术,就是一个Master数据库,多个Slave数据库.Master库负责数据更新和实时数据查询,Slave库当然负责非实时数据查询.因为在实际的应 ...

  8. LoadTest中内存和线程Troubleshooting实战

    LoadTest中内存和线程Troubleshooting实战 在端午节放假的三天中,我对正在开发的Service进行了LoadTest,尝试在增大压力的条件下发现问题. 该Service为独立进程的 ...

  9. openbr on linuxmint13/ubuntu12.04/debian7 x64 facial recognition [Compile from source!!!]

    Openbr is a great project for facial detecting. System: linuxmint 13 x86_64 Face recognition,  motio ...

  10. 腾讯地图api接收坐标提交坐标

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...