用javascript制作二位数的网页计算器
script部分
function add(clickNum){
document.getElementById("screen").value += clickNum.value;
}/*向屏幕增加数据*/function getResult(){
var str = document.getElementById("screen").value;
var ope,num1,num2;
if((ope = str.indexOf("+"))!=-1){
num1 = parseFloat(str.substring(0,ope));
num2 = parseFloat(str.substring(ope+1));
document.getElementById("screen").value = https://www.it610.com/article/num1 + num2;
}else if((ope = str.indexOf("-"))!=-1){
num1 = parseFloat(str.substring(0,ope));
num2 = parseFloat(str.substring(ope+1));
document.getElementById("screen").value = https://www.it610.com/article/num1 - num2;
}else if((ope = str.indexOf("*"))!=-1){
num1 = parseFloat(str.substring(0,ope));
num2 = parseFloat(str.substring(ope+1));
document.getElementById("screen").value = https://www.it610.com/article/num1 * num2;
}else if((ope = str.indexOf("/"))!=-1){
num1 = parseFloat(str.substring(0,ope));
num2 = parseFloat(str.substring(ope+1));
document.getElementById("screen").value = https://www.it610.com/article/num1 / num2;
}
}/*根据符号进行判断计算*/
function clears(){
document.getElementById("screen").valuehttps://www.it610.com/article/= "";
}/*清除函数*/
全部代码
网页计算器 - 锐客网 table input{
width:50px;
height:50px;
}/*设置按钮格式*/
#screen{
width:150px;
height:45px;
}/*设置屏幕格式*/
table {
border:1px solid #d0d0d0;
}
【用javascript制作二位数的网页计算器】效果
文章图片
除了JS计算器,在此送大家2020最新企业级 Vue3.0/Js/ES6/TS/React/node等实战视频教程,点击此处免费获取,小白勿进哦
推荐阅读
- Docker应用:容器间通信与Mariadb数据库主从复制
- JS中的各种宽高度定义及其应用
- 由浅入深理解AOP
- 【译】20个更有效地使用谷歌搜索的技巧
- 涉毒患者(新诗)
- 参保人员因患病来不及到指定的医疗机构就医,能否报销医疗费用()
- mybatisplus如何在xml的连表查询中使用queryWrapper
- MybatisPlus|MybatisPlus LambdaQueryWrapper使用int默认值的坑及解决
- MybatisPlus使用queryWrapper如何实现复杂查询
- 标签、语法规范、内联框架、超链接、CSS的编写位置、CSS语法、开发工具、块和内联、常用选择器、后代元素选择器、伪类、伪元素。