![]() |
#2
poyexyp2010-06-28 11:04
|

<style type="text/css">
<!--
.STYLE1 {
font-size: 12px;
color: #FF0000;
}
-->
</style>
<script language="javascript">
var expression;
function numAdd(cv){
/*
var num = document.form1.text1.value;
if (cv="+" || cv="-" || cv="*" || cv="/" )
{
document.form1.text1.value="";
}
if (num.charAt(0)="" || num.charAt(0)="+" || num.charAt(0)="-" || num.charAt(0)="*" || num.charAt(0)="/" )
{
alert("这样无法计算");
expression="";
}
*/
expression+=cv;
document.form1.text1.value=expression;
}
function compute(){
document.form1.text1.value=eval(expression);
expression=document.form1.text1.value;
}
function crt(){
expression="";
document.form1.text1.value="";
}
</script>
<form name="form1">
<table width="177" height="150" border="1" align="center" cellpadding="0" style="border:1px solid #9900CC ">
<tr>
<td colspan="4" align="center"> <span class="STYLE1">计算器</span></td>
</tr>
<tr>
<td colspan="4" align="center"><input type="text" name="text1" height="20" value=""></td>
</tr>
<tr>
<td width="40" align="center">
<input type="button" name="b1" value=" 1 " onClick="numAdd('1');"></td>
<td width="40" align="center"> <input type="button" name="b2" value=" 2 " onClick="numAdd('2');"></td>
<td width="40" align="center"> <input type="button" name="b3" value=" 3 " onClick="numAdd('3');"></td>
<td width="40" align="center"> <input type="button" name="bb" value=" / " onClick="numAdd('/');"></td>
</tr>
<tr>
<td width="40" align="center"> <input type="button" name="b4" value=" 4 " onClick="numAdd('4');"></td>
<td width="40" align="center"> <input type="button" name="b5" value=" 5 " onClick="numAdd('5');"></td>
<td width="40" align="center"> <input type="button" name="b6" value=" 6 " onClick="numAdd('6');"></td>
<td width="40" align="center"> <input type="button" name="bc" value=" * " onClick="numAdd('*');"></td>
</tr>
<tr>
<td width="40" align="center"> <input type="button" name="b7" value=" 7 " onClick="numAdd('7');"></td>
<td width="40" align="center"> <input type="button" name="b8" value=" 8 " onClick="numAdd('8');"></td>
<td width="40" align="center"> <input type="button" name="b9" value=" 9 " onClick="numAdd('9');"></td>
<td width="40" align="center"> <input type="button" name="bd" value=" - " onClick="numAdd('-');"></td>
</tr>
<tr>
<td width="40" align="center"> <input type="reset" name="be" value=" CE" onClick="crt();"></td>
<td align="center"><input type="button" name="bo" value=" 0 " onClick="numAdd('0');"></td>
<td align="center"><input type="button" name="ba" value=" = " onClick="compute();"></td>
<td width="40" align="center"> <input type="button" name="badd" value=" + " onClick="numAdd('+');"></td>
</tr>
</table>
</form>
<!--
.STYLE1 {
font-size: 12px;
color: #FF0000;
}
-->
</style>
<script language="javascript">
var expression;
function numAdd(cv){
/*
var num = document.form1.text1.value;
if (cv="+" || cv="-" || cv="*" || cv="/" )
{
document.form1.text1.value="";
}
if (num.charAt(0)="" || num.charAt(0)="+" || num.charAt(0)="-" || num.charAt(0)="*" || num.charAt(0)="/" )
{
alert("这样无法计算");
expression="";
}
*/
expression+=cv;
document.form1.text1.value=expression;
}
function compute(){
document.form1.text1.value=eval(expression);
expression=document.form1.text1.value;
}
function crt(){
expression="";
document.form1.text1.value="";
}
</script>
<form name="form1">
<table width="177" height="150" border="1" align="center" cellpadding="0" style="border:1px solid #9900CC ">
<tr>
<td colspan="4" align="center"> <span class="STYLE1">计算器</span></td>
</tr>
<tr>
<td colspan="4" align="center"><input type="text" name="text1" height="20" value=""></td>
</tr>
<tr>
<td width="40" align="center">
<input type="button" name="b1" value=" 1 " onClick="numAdd('1');"></td>
<td width="40" align="center"> <input type="button" name="b2" value=" 2 " onClick="numAdd('2');"></td>
<td width="40" align="center"> <input type="button" name="b3" value=" 3 " onClick="numAdd('3');"></td>
<td width="40" align="center"> <input type="button" name="bb" value=" / " onClick="numAdd('/');"></td>
</tr>
<tr>
<td width="40" align="center"> <input type="button" name="b4" value=" 4 " onClick="numAdd('4');"></td>
<td width="40" align="center"> <input type="button" name="b5" value=" 5 " onClick="numAdd('5');"></td>
<td width="40" align="center"> <input type="button" name="b6" value=" 6 " onClick="numAdd('6');"></td>
<td width="40" align="center"> <input type="button" name="bc" value=" * " onClick="numAdd('*');"></td>
</tr>
<tr>
<td width="40" align="center"> <input type="button" name="b7" value=" 7 " onClick="numAdd('7');"></td>
<td width="40" align="center"> <input type="button" name="b8" value=" 8 " onClick="numAdd('8');"></td>
<td width="40" align="center"> <input type="button" name="b9" value=" 9 " onClick="numAdd('9');"></td>
<td width="40" align="center"> <input type="button" name="bd" value=" - " onClick="numAdd('-');"></td>
</tr>
<tr>
<td width="40" align="center"> <input type="reset" name="be" value=" CE" onClick="crt();"></td>
<td align="center"><input type="button" name="bo" value=" 0 " onClick="numAdd('0');"></td>
<td align="center"><input type="button" name="ba" value=" = " onClick="compute();"></td>
<td width="40" align="center"> <input type="button" name="badd" value=" + " onClick="numAdd('+');"></td>
</tr>
</table>
</form>