123456789101112131415161718192021222324252627282930313233343536id="a"id="b"type="text" name="" id="answer" readonly="readonly"type="text" name="" id="answer2" readonly="readonly"id="c"type="button" name="" id="fs1" value="C" onclick="clean()"type="button" name="" id="fs2" value="<" onclick="del()"type="button" name="" id="fs3" value="+" onclick="jia()"type="button" name="" id="fs4" value="-" onclick="jian()"id="d"type="button" value="7" id="bs1" onclick="press(7)"type="button" value="8" id="bs2" onclick="press(8)"type="button" value="9" id="bs3" onclick="press(9)"type="button" name="" id="fs5" value="x" onclick="cheng()"id="e"type="button" name="" id="bs4" value="4" onclick="press(4)"type="button" name="" id="bs5" value="5" onclick="press(5)"type="button" name="" id="bs6" value="6" onclick="press(6)"type="button" name="" id="fs6" value="÷" onclick="chu()"id="f"type="button" name="" id="bs7" value="1" onclick="press(1)"type="button" name="" id="bs8" value="2" onclick="press(2)"type="button" name="" id="bs9" value="3" onclick="press(3)"type="button" name="" id="fs7" value="%" onclick="pressbf()"id="g"type="button" name="" id="fs8" value="+/-" onclick="jj()"type="button" name="" id="bs10" value="0" onclick="presszero()"type="button" name="" id="fs9" value="." onclick="pressdian()"type="button" name="" id="fs10" value="=" onclick="dy()"
1234567891011121314151617181920212223242526272829303132333435363738394041body {margin:0;padding:0;}#a {width:260px;background-color:#fff;margin:20px auto;text-align:center;border:aquamarine 1px solid;border-radius:90px;}#b #answer,#answer2 {margin-top:20px;font-size:14px;background:transparent;height:30px;width:190px;border:#fff solid 1px;outline:none;}#c input {padding:10px;margin:3px;width:40px;height:40px;outline:none;}#d input {padding:10px;margin:3px;width:40px;height:40px;outline:none;}#e input {padding:10px;margin:3px;width:40px;height:40px;outline:none;
12345678910111213141516171819202122232425262728293031323334353637383940414243// str 存储的为运算表达式 answer显示的为运算式或者点击等号后的最终结果 answer2为实时运算结果function dy() {if (str.substr(str.length - 1, 1) == "+" || str.substr(str.length - 1, 1) == "*" || str.substr(str.length - 1, 1) == "-" || str.substr(str.length - 1, 1) == "/") {str = str.substring(0, str.length - 1);answer2.value = Number(eval(str));str = answer2.value;answer.value = str;answer2.value = "";} else {str = answer2.value;answer.value = str;answer2.value = "";}// 函数为点击等号 第一行显示运算结果第二行清空}function clean() {// 点击c清空存储用字符串以及第一第二行显示内容str = "";answer.value = str;answer2.value = str;}function jj() {if (answer2.value != "") {if (answer2.value > 0)answer2.value = "-" + eval(str);else {str = answer2.value;str = str.substr(1, str.length - 1);answer2.value = str;}}}var str = "";// 用于存放要计算的表达式function chu() {if (str === "") {answer2.value = "";} else {// 使用截取表达式最后一位如果为运算符那么再次点击运算符时用新的运算符将其替换
更新时间:2020-03-17 00:24:56