<style type="text/css">
.style1 {
width: 23%;
height: 296px;
background-color:Black;
}
#txt_Result
{
height: 26px;
width: 191px;
text-align:right;
font-size:large;
}
input
{
width:50px;
height:25px;
}
</style>
<script type="text/javascript">
var n; //保存点击运算符前输入框中数字
var o; //存储对应运算符
function s(obj) { //数字键对应事件
var txt = document.getElementById("txt_Result");
if (txt.value.indexOf('.') > -1 && obj == '.') {
return false;
}
txt.value += obj;
}
function c(op) { //运算符(+,-,*,%)对应事件
n = document.getElementById('txt_Result').value;
document.getElementById('txt_Result').value = "";
o = op.value;
}
function qc() { //清除键对应事件
document.getElementById('txt_Result').value = "";
n = "";
o = "";
}
function e() { //等号对应事件
var s = document.getElementById('txt_Result');
if (o == '+') {
s.value =parseFloat(s.value) + parseFloat(n);
}
else if (o == '-') {
s.value = parseFloat(n) - parseFloat(s.value);
}
else if (o == '*') {
s.value = parseFloat(s.value) * parseFloat(n);
}
else {
s.value = parseFloat(n) / parseFloat(s.value);
}
n = "";
o = "";
}
function b() { //退格键对应事件
var s = document.getElementById('txt_Result');
s.value = s.value.substring(0, s.value.length - 1);
}
function ds() { //求倒数键对应事件
var s = document.getElementById('txt_Result');
s.value = 1 / parseFloat(s.value);
}
function square() { //平方键对应事件
var s = document.getElementById('txt_Result');
s.value = parseFloat(s.value) * parseFloat(s.value);
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div align="center">
<table class="style1">
<tr>
<td colspan="4">
<input id="txt_Result" type="text" /></td>
</tr>
<tr>
<td>
<input id="Button1" type="button" value="7" οnclick="s('7')"/></td>
<td>
<input id="Button2" type="button" value="8" οnclick="s('8')"/></td>
<td>
<input id="Button3" type="button" value="9" οnclick="s('9')"/></td>
<td>
<input id="Button4" type="button" value="←" οnclick="b()"/></td>
</tr>
<tr>
<td>
<input id="Button8" type="button" value="4" οnclick="s('4')"/></td>
<td>
<input id="Button7" type="button" value="5" οnclick="s('5')"/></td>
<td>
<input id="Button6" type="button" value="6" οnclick="s('6')"/></td>
<td>
<input id="Button5" type="button" value="+" οnclick="c(this)"/></td>
</tr>
<tr>
<td>
<input id="Button9" type="button" value="1" οnclick="s('1')"/></td>
<td>
<input id="Button10" type="button" value="2" οnclick="s('2')"/></td>
<td>
<input id="Button11" type="button" value="3" οnclick="s('3')"/></td>
<td>
<input id="Button12" type="button" value="-" οnclick="c(this)"/></td>
</tr>
<tr>
<td>
<input id="Button16" type="button" value="0" οnclick="s('0')"/></td>
<td>
<input id="Button15" type="button" value="." οnclick="s('.')"/></td>
<td>
<input id="Button14" type="button" value="=" οnclick="e()"/></td>
<td>
<input id="Button13" type="button" value="*" οnclick="c(this)"/></td>
</tr>
<tr>
<td>
<input id="Button17" type="button" value="1/x" οnclick="ds()"/></td>
<td>
<input id="Button18" type="button" value="x2" οnclick="square()"/></td>
<td>
<input id="Button19" type="button" value="Clear" οnclick="qc()"/></td>
<td>
<input id="Button20" type="button" value="%" οnclick="c(this)"/></td>
</tr>
</table>
.style1 {
width: 23%;
height: 296px;
background-color:Black;
}
#txt_Result
{
height: 26px;
width: 191px;
text-align:right;
font-size:large;
}
input
{
width:50px;
height:25px;
}
</style>
<script type="text/javascript">
var n; //保存点击运算符前输入框中数字
var o; //存储对应运算符
function s(obj) { //数字键对应事件
var txt = document.getElementById("txt_Result");
if (txt.value.indexOf('.') > -1 && obj == '.') {
return false;
}
txt.value += obj;
}
function c(op) { //运算符(+,-,*,%)对应事件
n = document.getElementById('txt_Result').value;
document.getElementById('txt_Result').value = "";
o = op.value;
}
function qc() { //清除键对应事件
document.getElementById('txt_Result').value = "";
n = "";
o = "";
}
function e() { //等号对应事件
var s = document.getElementById('txt_Result');
if (o == '+') {
s.value =parseFloat(s.value) + parseFloat(n);
}
else if (o == '-') {
s.value = parseFloat(n) - parseFloat(s.value);
}
else if (o == '*') {
s.value = parseFloat(s.value) * parseFloat(n);
}
else {
s.value = parseFloat(n) / parseFloat(s.value);
}
n = "";
o = "";
}
function b() { //退格键对应事件
var s = document.getElementById('txt_Result');
s.value = s.value.substring(0, s.value.length - 1);
}
function ds() { //求倒数键对应事件
var s = document.getElementById('txt_Result');
s.value = 1 / parseFloat(s.value);
}
function square() { //平方键对应事件
var s = document.getElementById('txt_Result');
s.value = parseFloat(s.value) * parseFloat(s.value);
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div align="center">
<table class="style1">
<tr>
<td colspan="4">
<input id="txt_Result" type="text" /></td>
</tr>
<tr>
<td>
<input id="Button1" type="button" value="7" οnclick="s('7')"/></td>
<td>
<input id="Button2" type="button" value="8" οnclick="s('8')"/></td>
<td>
<input id="Button3" type="button" value="9" οnclick="s('9')"/></td>
<td>
<input id="Button4" type="button" value="←" οnclick="b()"/></td>
</tr>
<tr>
<td>
<input id="Button8" type="button" value="4" οnclick="s('4')"/></td>
<td>
<input id="Button7" type="button" value="5" οnclick="s('5')"/></td>
<td>
<input id="Button6" type="button" value="6" οnclick="s('6')"/></td>
<td>
<input id="Button5" type="button" value="+" οnclick="c(this)"/></td>
</tr>
<tr>
<td>
<input id="Button9" type="button" value="1" οnclick="s('1')"/></td>
<td>
<input id="Button10" type="button" value="2" οnclick="s('2')"/></td>
<td>
<input id="Button11" type="button" value="3" οnclick="s('3')"/></td>
<td>
<input id="Button12" type="button" value="-" οnclick="c(this)"/></td>
</tr>
<tr>
<td>
<input id="Button16" type="button" value="0" οnclick="s('0')"/></td>
<td>
<input id="Button15" type="button" value="." οnclick="s('.')"/></td>
<td>
<input id="Button14" type="button" value="=" οnclick="e()"/></td>
<td>
<input id="Button13" type="button" value="*" οnclick="c(this)"/></td>
</tr>
<tr>
<td>
<input id="Button17" type="button" value="1/x" οnclick="ds()"/></td>
<td>
<input id="Button18" type="button" value="x2" οnclick="square()"/></td>
<td>
<input id="Button19" type="button" value="Clear" οnclick="qc()"/></td>
<td>
<input id="Button20" type="button" value="%" οnclick="c(this)"/></td>
</tr>
</table>