用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制作二位数的网页计算器】效果
用javascript制作二位数的网页计算器
文章图片

除了JS计算器,在此送大家2020最新企业级 Vue3.0/Js/ES6/TS/React/node等实战视频教程,点击此处免费获取,小白勿进哦

    推荐阅读