<!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. Vim搜索关键字

    有以下两种方法 Method 1:/content 默认从上往下查找 只读模式下输入 /content 后回车 按 n 向下查找 按N 向上查找 Method 2:?content 默认从下往上查找 ...

  2. ubuntu 安装nginx redis dotnet

    1 安装nginx sudo apt-get update sudo apt-get install nginx 配置文件 /etc/nginx/nginx.conf 2 安装redis sudo a ...

  3. python 多线程、线程锁、事件

    1. 多线程的基本使用 import threading import time def run(num): print('Num: %s'% num) time.sleep(3) if num == ...

  4. 【BZOJ1492】【Luogu P4027】 [NOI2007]货币兑换 CDQ分治,平衡树,动态凸包

    斜率在转移顺序下不满足单调性的斜率优化\(DP\),用动态凸包来维护.送命题. 简化版题意:每次在凸包上插入一个点,以及求一条斜率为\(K\)的直线与当前凸包的交点.思路简单实现困难. \(P.s\) ...

  5. vue history模式下的微信分享

    // 微信验证 export function requireConfig() { let url = window.location.href systemApi.wxoption({ url: u ...

  6. pyqt5-信号与槽

    个人理解:pyqt5的信号就是C++中事件,比如鼠标单击事件;pyqt5中的槽就是c++事件函数,比如单击之后要去执行的函数 例子一 一个信号连接一个槽 import sysfrom PyQt5.Qt ...

  7. 通过源码安装PostgresSQL

    通过源码安装PostgresSQL 1.1 下载源码包环境: Centos6.8 64位 yum -y install bison flex readline-devel zlib-devel yum ...

  8. 【SpringBoot】spring-session-data-redis 解决集群环境下session共享

    为什么会产生Session共享问题   集群情况下,session保存在各自的服务器的tomcat中,当分发地址至不同服务时,导致sesson取不到,就会产生session共享问题. 解决方案 负载均 ...

  9. EventArgs

    序言 DataEventArgs<DataSet> arg = new DataEventArgs<DataSet>(ds); 事件总线 什么是事件总线 我们知道事件是由一个P ...

  10. java文件断点续传的简单实现

    一.概述 所谓断点续传,其实只是指下载,也就是要从文件已经下载的地方开始继续下载.在以前版本的HTTP协议是不支持断点的,HTTP/1.1开始就支持了.一般断点下载时才用到Range和Content- ...