1 Star 0 Fork 0

geoyclv/better-coder

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
calculator.html 1.83 KB
一键复制 编辑 原始数据 按行查看 历史
yupili 提交于 2020-10-22 16:00 . add calculator 极简计算器
<!DOCTYPE html>
<html lang="en">
<head>
<title>计算器</title>
<meta charset="utf-8">
<style>
body {
padding: 20px;
user-select: none;
}
#wrapper {
width: 320px;
}
#result {
height: 100px;
border: 1px solid #ddd;
padding: 20px;
box-sizing: border-box;
}
.row {
display: flex;
column-count: 3;
}
.row button {
padding: 20px;
flex: 1;
font-size: 16px;
border: 1px solid #ddd;
background: #eee;
}
</style>
</head>
<body>
<div id="wrapper">
<div id="result"></div>
<div class="row">
<button>+</button>
<button>-</button>
<button id="ac">AC</button>
</div>
<div class="row">
<button>/</button>
<button>*</button>
<button id="getResult">=</button>
</div>
<div class="row">
<button>7</button>
<button>8</button>
<button>9</button>
</div>
<div class="row">
<button>4</button>
<button>5</button>
<button>6</button>
</div>
<div class="row">
<button>1</button>
<button>2</button>
<button>3</button>
</div>
<div class="row">
<button>%</button>
<button>0</button>
<button>.</button>
</div>
</div>
</body>
<script>
let buttonObjs = document.getElementsByTagName("button");
let resultObj = document.getElementById("result");
let acObj = document.getElementById("ac");
let getResultObj = document.getElementById("getResult");
for (const buttonObj of buttonObjs) {
if (!['AC', '='].includes(buttonObj.innerHTML)) {
buttonObj.addEventListener('click', () => {
resultObj.innerHTML += buttonObj.innerHTML;
})
}
}
acObj.addEventListener('click', () => {
resultObj.innerHTML = '';
})
getResultObj.addEventListener('click', () => {
resultObj.innerHTML = eval(resultObj.innerHTML);
})
</script>
</html>
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/geoyclv/better-coder.git
git@gitee.com:geoyclv/better-coder.git
geoyclv
better-coder
better-coder
master

搜索帮助