使用javascript的计算器(任何一个人可以帮助获得第一个值和第二个值,而不会在点击运算符时消失)。[英] calculator using javascript(any one can help to get first value and second value without disappearing the 1st value when clicking the operators)

问题描述

<html xmlns="http:///www.w3.org/1999/xhtml"><head><style type="text/css">表格{border-radius:15px;}</style>< http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>计算器</title><脚本 type="text/javascript">窗口.onload=函数(){文档.calculator.result.focus();}var 总计;var opr = 0;函数 display(val){文档.calculator.result.value+= val;}函数 txtclear(){文档.calculator.result.value='';}函数 运算符(opval){opr = opval;总计 = 文档.calculator.result.value;}函数 equals(){CValue = eval(document.calculator.result.value)PValue = eval(总计)if(opr =="+"){答案 = PValue + CValue;}else if(opr =="*"){答案 = PValue * CValue;}else if(opr =="-"){答案 = PValue - CValue;}else if(opr =="/"){答案 = PValue/CValue;}文档.calculator.result.value = answer;}功能框(e){var unicode=e.charCode?e.charCode : e.keyCodeif (unicode!=8 && unicode!=9 && unicode!=13){if (unicode<42 || unicode>57)return false;}if(unicode==13){等于();return false;}if(unicode==43){运算符("+");return false;}if(unicode==45){运算符("-");return false;}if(unicode==42){运算符("*");return false;}if(unicode==47){运算符("/");return false;}document.calculator.result.value='';}</脚本></head><body  bgcolor="#3CACA9"><form 名称="计算器"><table 宽度="248" height="309" border="3" bordercolor="#0099FF" align="center" style="margin-removed100px"><tr><td 高度="29" colspan="5" style="背景颜色:#09C;"><div style="color:#C09; font-weight:bolder; font-size:15px; " align="left">计算器</div></td></tr><tr><td 高度="56" colspan="5" style=" 背景颜色:#09C;"><输入 type="text" 名称="结果" style="height:100%; width:98.5%; text-align: right; font-family:Lucida Grande; font-size:45px;" onkeypress="返回框(事件)" /></td></tr><tr><td 宽度="43" height="52" align="center"><输入 type="button"  style="height:100%; width:100%; font-weight:bold" name="one" ="1"  onclick="display('1')" onmouseup="hello()" /></td><td 宽度="43" height="52" align="center"><输入 type="button" style="height:100%; width:100%; font-weight:bold" name="两个" ="2" onclick="display('2')" onmouseup="hello()" /></td><td 宽度="43" height="52" align="center"><输入 type="button" style="height:100%; width:100%; font-weight:bold" name="三个" ="3" onclick="display('3')"/></td><td 宽度="43" height="52" align="center"><输入 type="button" style="height:100%; width:100%; font-weight:bold" name="添加" ="+" onclick=operator("+") /></td><td 宽度="43" rowspan="4" align="center"><输入 type="button"  style="height:225px; width:100%; font-weight:bold" 名称="评估" ="=" onclick=equals() /></td></tr><tr><td 宽度="43" height="52" align="center"><输入 type="button" style="height:100%; width:100%; font-weight:bold" name="四个" ="4" onclick="display('4')"/></td><td 宽度="43" height="52" align="center"><输入 type="button" style="height:100%; width:100%; font-weight:bold" name="五个" ="5" onclick="display('5')"/></td><td 宽度="43" height="52" align="center"><输入 type="button" style="height:100%; width:100%; font-weight:bold" name="六" ="6" onclick="display('6')"/></td><td 宽度="43" height="52" align="center"><输入 type="button" style="height:100%; width:100%; font-weight:bold" name="subtract" ="-" onclick=operator("-") /></td></tr><tr><td 宽度="43" height="52" align="center"><输入 type="button" style="height:100%; width:100%; font-weight:bold" name="七" ="7" onclick="display('7')"/></td><td 宽度="43" height="52" align="center"><输入 type="button" style="height:100%; width:100%; font-weight:bold" name="八" ="8" onclick="display('8')"/></td><td 宽度="43" height="52" align="center"><输入 type="button" style="height:100%; width:100%; font-weight:bold" name="九个" ="9" onclick="display('9')"/></td><td 宽度="43" height="52" align="center"><输入 type="button" style="height:100%; width:100%; font-weight:bold" name="multiply" ="*" onclick=operator("*") /></td></tr><tr><td 宽度="43" height="52" align="center"><输入 type="button" style="height:100%; width:100%; font-weight:bold" name="dot" ="." onclick="display('.')"/></td><td 宽度="43" height="52" align="center"><输入 type="button" style="height:100%; width:100%; font-weight:bold" name="zero" value="0" onclick="display('0')"/></td><td width="43" height="52" align="center"><input type="button" style="height:100%; width:100%; font-weight:bold" name="clear" value="C" onclick="txtclear()"/></td><td width="43" height="52" align="center"><input type="button" style="height:100%; width:100%; font-weight:bold" name="divide" value="/" onclick=operator("/") /></td></tr></table></form></body></html>

推荐答案

Check this out:
http://javascriptsource.com/math-related/advanced.html[^]

Do you call it a calculator?

This is a calculator: http://sakryukov.org/freeware/calculator/[^].

—SA

本文地址:https://www.itbaoku.cn/post/1395096.html