| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 556 人关注过本帖
标题:一个计算器的问题,请帮忙分析分析..
只看楼主 加入收藏
Ronaldo1121
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2007-1-20
收藏
 问题点数:0 回复次数:0 
一个计算器的问题,请帮忙分析分析..

请问各位高手能不能把这里的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>

搜索更多相关主题的帖子: 计算器 
2007-01-20 21:54
快速回复:一个计算器的问题,请帮忙分析分析..
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.133600 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved