请问各位高手能不能把这里的javascript代码加上详细的注释,便于理解...
谢过!!!
<html>
<head>
<title>计算器</title>
<script language="javascript">
var total = 0;
var FlagNewNum = false;
var ppOp = "";
function enterNumber(num)
{
if (FlagNewNum)
{
document.form1.readout.value = num;
FlagNewNum = false;
}
else
{
if (document.form1.readout.value == "0")
document.form1.readout.value = num;
else
document.form1.readout.value += num;
}
}
function calculate (Op)
{
var readout = document.form1.readout.value;
if (FlagNewNum && ppOp != "=");
else
{
FlagNewNum = true;
if ( '+' == ppOp )
total += parseFloat(readout);
else if ( '-' == ppOp )
total -= parseFloat(readout);
else if ( '/' == ppOp )
total /= parseFloat(readout);
else if ( '*' == ppOp )
total *= parseFloat(readout);
else
total = parseFloat(readout);
document.form1.readout.value = total;
ppOp = Op;
}
}
function dd ()
{
var dian = document.form1.readout.value;
if (FlagNewNum)
{
dian = "0.";
FlagNewNum = false;
}
else
{
if (dian.indexOf(".") == -1)
dian += ".";
}
document.form1.readout.value = dian;
}
function Clear ()
{
total = 0;
ppOp = "";
document.form1.readout.value = "0";
FlagNewNum = true;
}
</script>
</head>
<body bgcolor="lavender">
<form name="form1" method="post" action="">
<table width="181" height="152" border="2" align="center" cellpadding="0" cellspacing="0">
<caption><b><font size="4" face="宋体" color="blue">我的小计算器</font><b></caption>
<tr>
<td height="38" colspan="5" align="center"><input name="readout" type="text" size="20"></td>
</tr>
<tr>
<td height="32" align="center"><input type="button" name="7" value=" 7 " onClick="enterNumber('7')"></td>
<td align="center"><input type="button" name="8" value=" 8 " onClick="enterNumber('8')"></td>
<td align="center"><input type="button" name="9" value=" 9 " onClick="enterNumber('9')"></td>
<td align="center"><input type="button" name="+" value=" + " onClick="calculate ('+')"></td>
<td align="center"><input type="button" name="C" value=" C " onClick="Clear()"></td>
</tr>
<tr>
<td height="26" align="center"><input type="button" name="4" value=" 4 " onClick="enterNumber('4')"></td>
<td align="center"><input type="button" name="5" value=" 5 " onClick="enterNumber('5')"></td>
<td align="center"><input type="button" name="6" value=" 6 " onClick="enterNumber('6')"></td>
<td align="center"><input type="button" name="-" value=" - " onClick="calculate ('-')"></td>
<td align="center"><input type="button" name="Submit2" value="^-^"></td>
</tr>
<tr>
<td height="25" align="center"><input type="button" name="1" value=" 1 " onClick="enterNumber('1')"></td>
<td align="center"><input type="button" name="2" value=" 2 " onClick="enterNumber('2')"></td>
<td align="center"><input type="button" name="3" value=" 3 " onClick="enterNumber('3')"></td>
<td align="center"><input type="button" name="*" value=" * " onClick="calculate ('*')"></td>
<td align="center"><input type="button" name="Submit3" value="^-^"></td>
</tr>
<tr>
<td height="25" align="center"><input type="button" name="0" value=" 0 " onClick="enterNumber('0')"></td>
<td align="center"><input type="button" name="Submit" value=" . " onClick="enterNumber('.')"></td>
<td align="center"><input type="button" name="/" value=" / " onClick="calculate ('/')"></td>
<td align="center"><input type="button" name="=" value=" = " onClick="calculate ('=')"></td>
<td align="center"><input type="button" name="Submit4" value="^-^"></td>
</tr>
</table>
</form>
</body>
</html>