Board logo

标题: 一个简单的计算器---请大家看看行不 [打印本页]

作者: happy99    时间: 2005-9-19 17:34     标题: 一个简单的计算器---请大家看看行不

点击查看效果

[此贴子已经被作者于2005-9-19 17:53:03编辑过]


作者: happy99    时间: 2005-9-19 19:07

就是那个1/x吧
可我想不出别的办法让它生效了
刚做的时候还可以用的

作者: tang688    时间: 2005-9-20 09:53

          <input name="invest" type="button" id="invest" onClick="invest();" value=" 1/x ">
看清楚了
你用了三次invest
它已搞不清那个是那个了
把函数名invest改一个
包你可用
作者: tang688    时间: 2005-9-20 09:54

[CODE] <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <meta http-equiv="Page-Enter" content="revealtrans(Duration=3,Transition=23)"> <title>计算器</title> <script language="javascript1.2" type="text/javascript"> var inputString=""; function updateString(value){ inputString+=value; document.Calculator.Input.value=inputString; } function other(){ inputString = eval(0-inputString); document.Calculator.Input.value=inputString; } function invest1(){ inputString =eval(1/inputString); document.Calculator.Input.value=inputString; } function sqrter(){ inputString = Math.sqrt(inputString); document.Calculator.Input.value=inputString; } </script> <style> a:link{text-decoration:none; color:#0066FF; font-size:12px; } a:visited{ text-decoration:none; color:#0066FF; font-style:normal; font-size: 12px; } a:hover {text-decoration:underline; color:#FF0000; font-weight:bold; font-size:14px; } a:active { text-decoration:none; color:#FF0000; font-size: 14px; }

body{ color:#666666; text-align:left; text-indent:inherit; background-color:transparency; scrollbar-face-color:#CCCCCC; scrollbar-highlight-color:#999999; scrollbar-shadow-color: #666666; scrollbar-arrow-color: #FF0000; scrollbar-base-color: #666666; scrollbar-dark-shadow-color: #666666; background-image: url(screen_bg.gif); border-bottom-width: 1px; border-top-style: none; border-right-style: none; border-bottom-style: dotted; border-left-style: none; border-bottom-color: #999999; font-size: 12px; margin-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; } </style> </head> <body leftmargin="0" topmargin="3" oncontextmenu="self.event.returnValue=false" onselectstart="return false"> <div align="center"><form action="" method="post" name="Calculator" id="Calculator"> <table width="356" border="4" cellpadding="2" cellspacing="1" bordercolorlight="#999999" bordercolordark="#333333" bgcolor="#CCCCCC"> <tr> <td height="29" colspan="5"><div align="right"> <font size="2" color="#0000FF"><a href="http://myhappy99.icpcn.com" target="_blank">☆默鸣小站欢迎您☆</a></font> <input name="Input" type="text" style="height:20 " size="26" maxlength="100" align="right"> </div></td> </tr> <tr> <td> <div align="center"> <input name="seven" type="button" id="seven" onClick="updateString('7')" value=" 7 "> </div></td> <td> <div align="center"> <input name="eight" type="button" id="eight" onClick="updateString('8')" value=" 8 "> </div></td><td><div align="center"> <input name="nine" type="button" id="nine" onClick="updateString('9')" value=" 9 "> </div></td> <td><div align="center"> <input type="button" name="plus" value=" + " onClick="updateString('+')"> </div></td> <td><div align="center"> <input name="sqrt" type="button" id="sqrt" value=" sqr " onClick="sqrter();"> </div></td> </tr> <tr> <td><div align="center"> <input name="four" type="button" id="four" onClick="updateString('4')" value=" 4 "> </div></td> <td><div align="center"> <input name="five" type="button" id="five" onClick="updateString('5')" value=" 5 "> </div></td> <td><div align="center"> <input name="six" type="button" id="six" onClick="updateString('6')" value=" 6 "> </div></td> <td><div align="center"> <input type="button" name="minus" value=" - " onClick="updateString('-')"> </div></td> <td><div align="center"> <input name="invest" type="button" id="invest" onClick="invest1();" value=" 1/x "> </div></td> </tr> <tr> <td><div align="center"> <input name="one" type="button" id="one" onClick="updateString('1')" value=" 1 "> </div></td> <td><div align="center"> <input name="two" type="button" id="two" onClick="updateString('2')" value=" 2 "> </div></td> <td><div align="center"> <input name="three" type="button" id="three" onClick="updateString('3')" value=" 3 "> </div></td> <td><div align="center"> <input type="button" name="times" value=" * " onClick="updateString('*')"> </div></td> <td><div align="center"> <input name="clear" type="button" id="clear" onClick="Input.value='';inputString=''" value="clear"> </div></td> </tr> <tr> <td><div align="center"> <input name="zero" type="button" id="zero" onClick="updateString('0')" value=" 0 "> </div></td> <td><div align="center"> <input name="plu/min" type="button" id="plu/min" onClick="other();" value=" +/- "> </div></td> <td><div align="center"> <input name="dot" type="button" id="dot" onClick="updateString('.')" value=" . "> </div></td> <td><div align="center"> <input type="button" name="div" value=" / " onClick="updateString('/')"> </div></td> <td><div align="center"> <input name="equal" type="button" id="equal" onClick="document.Calculator.Input.value=eval(inputString);" value=" = "> </div></td> </tr> <tr><td align=center colspan=5><font size=2>Copyright 2005-2006 &copy;&nbsp;Moming All Rights Reserved <a href="mailtmyhappy99@gmail.com?subject=My%20advice" title="给我提提意见^_^">Myhappy99@gmail.com </a></font></td></tr> </table> </form> </div> </body> </html> [/CODE]


作者: happy99    时间: 2005-9-20 12:41

谢谢指教
作者: 清澂居士    时间: 2007-1-9 11:31

以下是引用tang688在2005-9-20 9:54:00的发言:

[CODE]
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta http-equiv="Page-Enter" content="revealtrans(Duration=3,Transition=23)">
<title>计算器</title>
<script language="javascript1.2" type="text/javascript">
var inputString="";
function updateString(value){
inputString+=value;
document.Calculator.Input.value=inputString;
}
function other(){
inputString = eval(0-inputString);
document.Calculator.Input.value=inputString;
}
function invest1(){
inputString =eval(1/inputString);
document.Calculator.Input.value=inputString;
}
function sqrter(){
inputString = Math.sqrt(inputString);
document.Calculator.Input.value=inputString;
}
</script>
<style>
a:link{text-decoration:none;
color:#0066FF;
font-size:12px;
}
a:visited{
text-decoration:none;
color:#0066FF;
font-style:normal;
font-size: 12px;
}
a:hover {text-decoration:underline;
color:#FF0000;
font-weight:bold;
font-size:14px;
}
a:active {
text-decoration:none;
color:#FF0000;
font-size: 14px;
}

body{
color:#666666;
text-align:left;
text-indent:inherit;
background-color:transparency;
scrollbar-face-color:#CCCCCC;
scrollbar-highlight-color:#999999;
scrollbar-shadow-color: #666666;
scrollbar-arrow-color: #FF0000;
scrollbar-base-color: #666666;
scrollbar-dark-shadow-color: #666666;
background-image: url(screen_bg.gif);
border-bottom-width: 1px;
border-top-style: none;
border-right-style: none;
border-bottom-style: dotted;
border-left-style: none;
border-bottom-color: #999999;
font-size: 12px;
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
}
</style>
</head>
<body leftmargin="0" topmargin="3" oncontextmenu="self.event.returnValue=false" onselectstart="return false">
<div align="center"><form action="" method="post" name="Calculator" id="Calculator">
<table width="356" border="4" cellpadding="2" cellspacing="1" bordercolorlight="#999999" bordercolordark="#333333" bgcolor="#CCCCCC">
<tr>
<td height="29" colspan="5"><div align="right">
<font size="2" color="#0000FF"><a href="http://myhappy99.icpcn.com" target="_blank">☆默鸣小站欢迎您☆</a></font>
<input name="Input" type="text" style="height:20 " size="26" maxlength="100" align="right">
</div></td>
</tr>
<tr>
<td>
<div align="center">
<input name="seven" type="button" id="seven" onClick="updateString('7')" value=" 7 ">
</div></td>
<td>
<div align="center">
<input name="eight" type="button" id="eight" onClick="updateString('8')" value=" 8 ">
</div></td><td><div align="center">
<input name="nine" type="button" id="nine" onClick="updateString('9')" value=" 9 ">
</div></td>
<td><div align="center">
<input type="button" name="plus" value=" + " onClick="updateString('+')">
</div></td>
<td><div align="center">
<input name="sqrt" type="button" id="sqrt" value=" sqr " onClick="sqrter();">
</div></td>
</tr>
<tr>
<td><div align="center">
<input name="four" type="button" id="four" onClick="updateString('4')" value=" 4 ">
</div></td>
<td><div align="center">
<input name="five" type="button" id="five" onClick="updateString('5')" value=" 5 ">
</div></td>
<td><div align="center">
<input name="six" type="button" id="six" onClick="updateString('6')" value=" 6 ">
</div></td>
<td><div align="center">
<input type="button" name="minus" value=" - " onClick="updateString('-')">
</div></td>
<td><div align="center">
<input name="invest" type="button" id="invest" onClick="invest1();" value=" 1/x ">
</div></td>
</tr>
<tr>
<td><div align="center">
<input name="one" type="button" id="one" onClick="updateString('1')" value=" 1 ">
</div></td>
<td><div align="center">
<input name="two" type="button" id="two" onClick="updateString('2')" value=" 2 ">
</div></td>
<td><div align="center">
<input name="three" type="button" id="three" onClick="updateString('3')" value=" 3 ">
</div></td>
<td><div align="center">
<input type="button" name="times" value=" * " onClick="updateString('*')">
</div></td>
<td><div align="center">
<input name="clear" type="button" id="clear" onClick="Input.value='';inputString=''" value="clear">
</div></td>
</tr>
<tr>
<td><div align="center">
<input name="zero" type="button" id="zero" onClick="updateString('0')" value=" 0 ">
</div></td>
<td><div align="center">
<input name="plu/min" type="button" id="plu/min" onClick="other();" value=" +/- ">
</div></td>
<td><div align="center">
<input name="dot" type="button" id="dot" onClick="updateString('.')" value=" . ">
</div></td>
<td><div align="center">
<input type="button" name="div" value=" / " onClick="updateString('/')">
</div></td>
<td><div align="center">
<input name="equal" type="button" id="equal" onClick="document.Calculator.Input.value=eval(inputString);" value=" = ">
</div></td>
</tr>
<tr><td align=center colspan=5><font size=2>Copyright 2005-2006 &copy;&nbsp;Moming All Rights Reserved <a href="mailtmyhappy99@gmail.com?subject=My%20advice" title="给我提提意见^_^">Myhappy99@gmail.com </a></font></td></tr>
</table>
</form>
</div>
</body>
</html>
[/CODE]

確實厲害```


作者: 独爱青    时间: 2008-6-24 20:00

我什么时候才可以到这境界呀!
高手就事不一样啊!

作者: jxdz086465    时间: 2008-7-4 18:00


作者: axi2358    时间: 2008-7-20 00:03     标题: ..


作者: ming206    时间: 2008-7-26 01:11

真晕...........
作者: SkyGull    时间: 2008-8-1 13:05

有错误

我的操作是
9 + 9 = +
就会出错了
作者: 风之舞鹤    时间: 2008-8-7 13:49

这个计算器不支持非常规操作




欢迎光临 编程论坛 (https://bbs.bccn.net/) Powered by Discuz! 6.1.0