<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | |
<html xmlns="http://www.w3.org/1999/xhtml"> | |
<head> | |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> | |
<title>无标题文档</title> | |
<style> | |
table{ text-align:center;} | |
#main{ width:350px; height:35px; font-size:25px; border-left: 2px solid #333; border-top: 2px solid #333; border-bottom:1px solid #CCC; border-right:1px solid #CCC;} | |
input{ width:90px; height:30px; } | |
</style> | |
<script> | |
var initData = ""; | |
var lastop = ""; | |
var number1 = 0; | |
var number2 = 0; | |
var opflag = 0; | |
var res = 0; | |
function clearAll(){ | |
initData = ""; | |
lastop = ""; | |
number1 = 0; | |
number2 = 0; | |
opflag = 0; | |
res = 0; | |
Display("0."); | |
} | |
function clearErr(){ | |
initData = initData.substring(0,initData.length-1); | |
Display(initData); | |
} | |
function getNum(Data){ | |
initData += Data; | |
Display(initData); | |
} | |
function Display(data){ | |
document.getElementById("main").value=data; | |
} | |
function getop(op){ | |
lastop = op; | |
if(opflag == 1){ | |
return; | |
} | |
else{ | |
number1 = parseFloat(initData); | |
initData = ""; | |
} | |
opflag = 1; | |
} | |
function result(){ | |
number2 = parseFloat(initData); | |
switch(lastop){ | |
case '+':res = number1+number2;break; | |
case '-':res = number1-number2;break; | |
case '*':res = number1*number2;break; | |
case '/':res = number1/number2;break; | |
case '%':res = number1%number2; | |
} | |
Display(res); | |
initData = ""; | |
opflag = 0; | |
} | |
</script> | |
</head> | |
<body> | |
<form> | |
<table width="700" border="1" align="center"> | |
<tr> | |
<td height="50" colspan="3"> | |
<input type="text" id="main" value="" /> | |
</td> | |
<td width="140"> | |
<input type="button" value="C" onclick="clearAll()" /> | |
</td> | |
<td width="140"> | |
<input type="button" value="CE" onclick="clearErr()" /> | |
</td> | |
</tr> | |
<tr> | |
<td width="140" height="40"> | |
<input type="button" value="7" onclick="getNum('7')" /> | |
</td> | |
<td width="140"> | |
<input type="button" value="8" onclick="getNum('8')" /> | |
</td> | |
<td width="140"> | |
<input type="button" value="9" onclick="getNum('9')" /> | |
</td> | |
<td> | |
<input type="button" value="+/-" onclick="getop('+/-')" /> | |
</td> | |
<td> | |
<input type="button" value="%" onclick="getop('%')" /> | |
</td> | |
</tr> | |
<tr> | |
<td height="40"> | |
<input type="button" value="4" onclick="getNum('4')" /> | |
</td> | |
<td> | |
<input type="button" value="5" onclick="getNum('5')" /> | |
</td> | |
<td> | |
<input type="button" value="6" onclick="getNum('6')" /> | |
</td> | |
<td> | |
<input type="button" value="+" onclick="getop('+')" /> | |
</td> | |
<td> | |
<input type="button" value="-" onclick="getop('-')" /> | |
</td> | |
</tr> | |
<tr> | |
<td height="40"> | |
<input type="button" value="1" onclick="getNum('1')" /> | |
</td> | |
<td> | |
<input type="button" value="2" onclick="getNum('2')" /> | |
</td> | |
<td> | |
<input type="button" value="3" onclick="getNum('3')" /> | |
</td> | |
<td> | |
<input type="button" value="*" onclick="getop('*')" /> | |
</td> | |
<td> | |
<input type="button" value="/" onclick="getop('/')" /> | |
</td> | |
</tr> | |
<tr> | |
<td height="40"> | |
<input type="button" value="0" onclick="getNum('0')" /> | |
</td> | |
<td> | |
<input type="button" value="." onclick="getNum('.')" /> | |
</td> | |
<td> </td> | |
<td> | |
<input type="button" value="=" onclick="result();" /> | |
</td> | |
<td> | |
<input type="button" value="返回" /> | |
</td> | |
</tr> | |
</table> | |
</form> | |
</body> | |
</html> | |
Java Web计算器。
最新推荐文章于 2023-03-15 09:13:35 发布