web学习之js写计算器,学前端程序开发

28 阅读3分钟

.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: #f1cd00;

box-shadow: 0 5px #76ee05d0;

color: #131312;

}

.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: #6df811;

box-shadow: 0 5px #0b3cf0;

}

.operator:hover {

background-color: rgba(233, 233, 17, 0.6);

color: #0937f0;

}

.other {

background-color: rgba(240, 10, 201, 0.7);

box-shadow: 0 5px #02f0f0;

}

.other:hover {

background-color: rgba(8, 190, 245, 0.4);

color: #dededc;

}

.button_clear {

margin-left: 10px;

padding: 5px;

outline: none;

border-radius: 25px;

background-color: rgb(248, 247, 247);

color: rgb(0, 10, 10);

font-size: 16px;

font-style: strong;

width: 80px;

height: 28px;

}

.button_clear:active {

background-color: rgb(10, 252, 10);

box-shadow: 0 5px #666;

transform: translateY(2px);

}

.button_back {

margin-left: 58px;

padding: 5px;

outline: none;

border-radius: 25px;

background-color: rgb(250, 245, 243);

color: rgb(0, 0, 0);

font-size: 16px;

font-style: strong;

width: 80px;

height: 28px;

}

.button_back:active {

background-color: rgb(10, 247, 10);

box-shadow: 0 5px #666;

transform: translateY(2px);

}

.off_on {

margin-left: 20px;

padding: 5px;

outline: none;

border-radius: 25px;

background-color: rgb(250, 245, 243);

color: rgb(17, 18, 19);

font-size: 16px;

font-style: strong;

width: 60px;

height: 28px;

}

.off_on:active {

background-color: rgb(7, 252, 39);

box-shadow: 0 5px #666;

transform: translateY(2px);

}

p,

h1 {

font-family: 楷体;

}

js部分:

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 = "欢迎使用PJ牌";

setTimeout(welcome_end, 1000);

};

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 isInteger(obj){

return typeof obj === 'number' && obj%1 === 0; //是整数,则返回true,否则返回false

}

function calculates() {

if (power == 1) {

var result = 0;

result = document.getElementById("display").value;

var flag = isInteger(eval(result));

if(!flag)

document.getElementById("display").value = eval(result).toFixed(8);

else

document.getElementById("display").value = eval(result);

} else {

document.getElementById("display").value = "";

}

};

文末

逆水行舟不进则退,所以大家要有危机意识。

同样是干到35岁,普通人写业务代码划水,榜样们深度学习拓宽视野晋升管理。

这也是为什么大家都说35岁是程序员的门槛,很多人迈不过去,其实各行各业都是这样都会有个坎,公司永远都缺的高级人才,只用这样才能在大风大浪过后,依然闪耀不被公司淘汰不被社会淘汰。

为了帮助大家更好温习重点知识、更高效的准备面试,特别整理了《前端工程师核心知识笔记》电子稿文件。

内容包括html,css,JavaScript,ES6,计算机网络,浏览器,工程化,模块化,Node.js,框架,数据结构,性能优化,项目等等。

269页《前端大厂面试宝典》

包含了腾讯、字节跳动、小米、阿里、滴滴、美团、58、拼多多、360、新浪、搜狐等一线互联网公司面试被问到的题目,涵盖了初中级前端技术点。

前端面试题汇总

开源分享:docs.qq.com/doc/DSmRnRG…