<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="keywords" content="Calculator">
<meta name="description" content="Calculator">
<meta name="author" content="LIEGE">
<title>Calculator</title> <style> * {
border: none;
margin: 0;
padding: 0;
}
body { }
.center {
background-color: #fff;
border-radius: 50%;
height: 800px;
margin: auto;
width: 800px;
}
h1 {
color: #495678
font-size: 30px;
margin-top: 20px;
padding-top: 50px;
display: block;
text-align: center;
text-decoration: none;
} form {
background-color: #495678;
box-shadow: 10px 10px #3d4a65;
margin: 40px auto;
padding: 40px 0px 30px 30px;
width: 200px;
} .btn {
outline: none;
font-size: 20px;
height: 45px;
margin: 5px 0 5px 10px;
width: 45px;
}
.btn:first-child {
margin: 5px 0 5px 10px;
} #display {
outline: none;
background-color: white;
color: black;
font-size: 20px;
height: 47px;
text-align: right;
width: 165px;
padding-right: 10px;
margin-left: 0px;
}
.btn, #display, form {
border-radius: 25px;
} .number {
background-color: #72778b;
box-shadow: 0 5px #5f6680;
color: #dededc;
}
.number:active {
box-shadow: 0 2px #5f6680;
-webkit-transform: translateY(2px);
-ms-transform: translateY(2px);
-moz-tranform: translateY(2px);
transform: translateY(2px);
}
.number:hover {
background-color: rgb(114,119,139,0.4);
box-shadow: 0 5px #5f6680;
color: #dededc;
} .operator {
background-color: #dededc;
color: #72778b;
} .operator:hover {
background-color:rgb(222,222,220,0.6);
color: #72778b;
} .other {
background-color:rgb(255,0,0,0.7);
color:#dededc ;
}
.other:hover {
background-color:rgb(255,0,0,0.4);
color:#dededc ;
} .button_clear{
outline: none;
border-radius: 25px;
background-color:#FF4500;
color:#FFFF00;
font-size:16px;
font-style:strong;
width:40px;
height:28px; }
.button_clear:active {
background-color: red;
box-shadow: 0 5px #666;
transform: translateY(2px);
}
.off_on{
outline: none;
border-radius: 25px;
background-color:#FF4500;
color:#FFFF00;
font-size:16px;
font-style:strong;
width:40px;
height:28px;
}
.off_on:active{
background-color: red;
box-shadow: 0 5px #666;
transform: translateY(2px);
}
.tishi{
font-size:10px;
text-decoration:none;
}
</style>
<script>
var power = 1;
// 1 是开机 -1是关机
function off(){//一开始就运行---》 关机
power = -power;
if(power == -1){
document.getElementById("display").value = "";
}else{
welcome();
} };
function clearout(){
if(power == -1){
document.getElementById("display").value = "";
}else{
document.getElementById("display").value = "";
document.getElementById("display").focus();
}
};
function welcome(){
document.getElementById("display").value = "Welcome ☺";
setTimeout(welcome_end, 2000);
};
function welcome_end(){
document.getElementById("display").value = "";
document.getElementById("display").focus();
}; function get(value) {
if(power == 1){
document.getElementById("display").value += value;
}else{
document.getElementById("display").value = "";
} } ;
function back(){
if(power == 1){
var now_result = document.getElementById("display"); //*****************************
document.getElementById("display").value = now_result.value.substring(0, now_result.value.length - 1);
}else{
document.getElementById("display").value = "";
} }; function calculates() {
if(power == 1){
var result = 0;
result = document.getElementById("display").value;
document.getElementById("display").value = "";
document.getElementById("display").value = eval(result);
}else{
document.getElementById("display").value = "";
} };
function tishi(){
confirm("按钮 C 清零 \n按钮 OFF 开/关机\n按钮 B 退格");
};
</script>
</head>
<body link="grey" vlink="grey" alink="grey" Onload="off()">
<div class="center">
<h1 >Unbrealla™ Calculator <a href="#" onclick="tishi()" class="tishi">HELP</a></h1>
<form name="calculator"> <input type="text" id="display" width="300px" value="">
<br>
<br><input type="button" class="button_clear" value="C" onclick="clearout();">
<input type="button" class="off_on" value="OFF" onclick="off();">
<input type="button" class="off_on" value="B" onclick="back();">
<br>
<input type="button" class="btn number" value="1" onclick="get(this.value);">
<input type="button" class="btn number" value="2" onclick="get(this.value);">
<input type="button" class="btn number" value="3" onclick="get(this.value);">
<br />
<input type="button" class="btn number" value="4" onclick="get(this.value);">
<input type="button" class="btn number" value="5" onclick="get(this.value);">
<input type="button" class="btn number" value="6" onclick="get(this.value);">
<br />
<input type="button" class="btn number" value="7" onclick="get(this.value);">
<input type="button" class="btn number" value="8" onclick="get(this.value);">
<input type="button" class="btn number" value="9" onclick="get(this.value);">
<br /> <input type="button" class="btn number" value="0" onclick="get(this.value);">
<input type="button" class="btn operator" value="-" onclick="get(this.value);">
<input type="button" class="btn operator" value="+" onclick="get(this.value);">
<br /> <input type="button" class="btn operator" value="*" onclick="get(this.value);">
<input type="button" class="btn operator" value="/" onclick="get(this.value);">
<input type="button" class="btn other" value="=" onclick="calculates();">
</form>
</div> </body>
</html>

JavaScript —— 实现简单计算器【带有 开/关机 清零 退格 功能】的更多相关文章

  1. JAVASCRIPT实现简单计算器

    最终效果如下图-2,有bug:就是整数后点击%号结果正确,如果小数后面点击%的话结果就错误!其他都正常,求指点:input的value是string类型的,在JS中改如何正确处理下图-1中的if部分? ...

  2. 学习笔记之javascript编写简单计算器

      感觉自己的的实力真的是有待提高,在编写计算器的过程中,出现了各种各样的问题,暴露了自己的基础不扎实,逻辑思维能力不够,学得知识不能运用到自己的demo中区.先介绍一些这个这个计算器的整体思路.大致 ...

  3. 用javascript编写的简单计算器

    老师布置的任务,弄了一天,总算把代码搞出来了,作为菜鸟给自己一点小掌声,传说中JS是很简单的,但是要写出一个程序真的很需要锻炼,我的锻炼实在是太少了,天天DOTA中.呵呵(做了些小注释)大家应该能看懂 ...

  4. javascript简单计算器实践

    参考部分资料,编写一个简单的计算器案例,虽然完成了正常需求,但是也有不满之处,待后续实力提升后再来补充,先把不足之处列出: 1:本来打算只要打开页面,计算器的输入框会显示一个默认为0的状态,但是在输入 ...

  5. JavaScript+HTML,简单的计算器实现

    成功进化到程序猿快一年多了, 还没写过计算器, 正好今天比较闲,随手写了个计算器,最简单的实现,核心是eval()方法,把字符串作为JS代码处理,把输入的信息拼接成字符串,点等号执行代码得到结果,出异 ...

  6. 用JavaScript制作简单的计算器

    <html > <head> <title>简单计算器</title> <style type="text/css"> ...

  7. Linux——系统开关机指令简单学习笔记

    关机: 命令名称:shutdown 命令所在路径:/usr/sbin/shutdown 执行权限:root 语法:shutdown 功能描述:关机 范例:# shutdown -h now 重启: 命 ...

  8. 利用css和javascript实现简单的计算器

    <!doctype html> <html> <head> <!--声明当前页面的编码集--> <meta http-equiv="Co ...

  9. 菜鸟学Android编程——简单计算器《一》

    菜鸟瞎搞,高手莫进 本人菜鸟一枚,最近在学Android编程,网上看了一些视频教程,于是想着平时手机上的计算器应该很简单,自己何不尝试着做一个呢? 于是就冒冒失失的开撸了. 简单计算器嘛,功能当然很少 ...

随机推荐

  1. Ubuntu18.04 安装redis

    Redis是常用基于内存的Key-Value数据库,比Memcache更先进,支持多种数据结构,高效,快速.用Redis可以很轻松解决高并发的数据访问问题:作为实时监控信号处理也非常不错. 安装red ...

  2. python打印实心等边三角形和空心等边三角形

    #1 打印实心等边三角形 n = 5 for i in range(1, n+1): # 控制三角形的高,也就是层数 for k in range(2*(n-i)): # 控制每层第一个*的空格,从最 ...

  3. multi gpu inference with tfserving or keras

    在tfserving上,目测只能在每个gpu上起docker    https://github.com/tensorflow/serving/issues/311#issuecomment-4801 ...

  4. BZOJ 4999 LCA树状数组差分维护DFS序

    Description 给一颗树,每个节点有个初始值 现在支持以下两种操作: 1. C i x(0<=x<2^31) 表示将i节点的值改为x 2. Q i j x(0<=x<2 ...

  5. 用jquery控制表单提交

    可以监听表单submit提交事件给form一个id 吧button的type为submit $(form的id).submit(function(){ if(window.confirm('你确定要取 ...

  6. Struts 2 配置Action详解_java - JAVA

    文章来源:嗨学网 敏而好学论坛www.piaodoo.com 欢迎大家相互学习 实现了Action处理类之后,就可以在struts.xml中配置该Action,从而让Struts 2框架知道哪个Act ...

  7. web开发常见的几大安全问题

    一.SQL注入 SQL注入是一种常见的Web安全漏洞,攻击者利用这个漏洞,可以访问或修改数据,或者利用潜在的数据库漏洞进行攻击.SQL注入,就是通过把SQL命令插入到Web表单提交或输入域名或页面请求 ...

  8. windows 环境如何启动 redis ?

    1.cd 到 redis 的安装目录 C:\Users\dell>cd C:\redis 2.执行 redis 启动命令 C:\redis>redis-server.exe redis.w ...

  9. mfc static控件 视频播放 闪屏问题 解决方案

    方案1: 我昨天刚在csdn上解决了这个问题,不是双缓冲和WS_CLIPCHILDREN还有背景擦出什么的问题,就是在你重画的时候要去掉这些控件(按钮什么的)区域, 闪屏是因为窗口大小发生改变时,由于 ...

  10. windows下 申请免费ssl证书的方法 (letsencrypt)

    Let's Encrypt,官网是https://letsencrypt.org/,它是一个由各大公司赞助的公益组织: 有趋势有需求,自然也有免费可用.免费的SSL证书中,首推就是Let's Encr ...