TShopping

 找回密碼
 註冊
搜索
查看: 1300|回復: 3

[教學] 線上計算機(精簡版)

[複製鏈接]
發表於 2008-9-23 23:13:58 | 顯示全部樓層 |閱讀模式
 
Push to Facebook Push to Plurk Push to Twitter 
來源 : http://home.anet.net.tw/bviwy666/

語法如下
  1. <center>
  2. <p>
  3. <style><!-- a{text-decoration:none} --></style>
  4. <style type="text/css">a:hover{text-decoration:;color:#ff0000}</style>

  5. </head><body background="../images/background/whbrik_w.jpg">
  6. </p>
  7. </center>

  8. <div align="center">
  9. <center>




  10. <p align="center"><b><font face="標楷體" size="6" color="#0000FF">線上計算機</font></b><font face="標楷體" size="6" color="#0000FF"><br>
  11. </font>
  12. <form name="Keypad" action>
  13. <table border="1" width="249" height="60" cellpadding="0" cellspacing="1" bordercolorlight="#CCCCCC" bordercolordark="#999999" bordercolor="#CCCCCC" bgcolor="#666666">
  14. <tr>
  15. <td colspan="4" align="middle"><input name="ReadOut" type="Text" size="30" value="0" width="100%" class="text_input"></td>
  16. <td width="0"> </td>
  17. <td width="50"><input name="btnClear" type="Button" value=" C " onclick="Clear()" class="Button"></td>
  18. <td><input name="btnClearEntry2" type="Button" value=" CE " onClick="ClearEntry()" class="Button"></td>
  19. </tr>
  20. <tr>
  21. <td width="50"><input name="btnSeven" type="Button" value=" 7 " onclick="NumPressed(7)" class="Button"></td>
  22. <td width="50"><input name="btnEight" type="Button" value=" 8 " onclick="NumPressed(8)" class="Button"></td>
  23. <td width="50"><input name="btnNine" type="Button" value=" 9 " onclick="NumPressed(9)" class="Button"></td>
  24. <td width="50"><input name="btnHex" type="Button" value="HEX" onClick="hexchange()" class="Button"></td>
  25. <td width="0"> </td>
  26. <td width="50"><input name="btnNeg" type="Button" value=" +/- " onclick="Neg()" class="Button"></td>
  27. <td><input name="btnPercent" type="Button" value=" % " onClick="ercent()" class="Button"></td>
  28. </tr>
  29. <tr>
  30. <td width="50"><input name="btnFour" type="Button" value=" 4 " onclick="NumPressed(4)" class="Button"></td>
  31. <td width="50"><input name="btnFive" type="Button" value=" 5 " onclick="NumPressed(5)" class="Button"></td>
  32. <td width="50"><input name="btnSix" type="Button" value=" 6 " onclick="NumPressed(6)" class="Button"></td>
  33. <td width="50"><input name="btnClearEntry222" type="Button" value="OCT" onClick="octchange()" class="Button"></td>
  34. <td width="0"> </td>
  35. <td align="middle" width="50"><input name="btnPlus" type="Button" value=" + " onclick="Operation('+')" class="Button"></td>
  36. <td align="middle"><input name="btnMinus" type="Button" value=" - " onClick="Operation('-')" class="Button"></td>
  37. </tr>
  38. <tr>
  39. <td width="50"><input name="btnOne" type="Button" value=" 1 " onclick="NumPressed(1)" class="Button"></td>
  40. <td width="50"><input name="btnTwo" type="Button" value=" 2 " onclick="NumPressed(2)" class="Button"></td>
  41. <td width="50"><input name="btnThree" type="Button" value=" 3 " onclick="NumPressed(3)" class="Button"></td>
  42. <td width="50"><input name="btnClearEntry223" type="Button" value="BIN" onClick="binchange()" class="Button"></td>
  43. <td width="0"> </td>
  44. <td align="middle" width="50"><input name="btnMultiply" type="Button" value=" * " onclick="Operation('*')" class="Button"></td>
  45. <td align="middle"><input name="btnDivide" type="Button" value=" / " onClick="Operation('/')" class="Button"></td>
  46. </tr>
  47. <tr>
  48. <td width="50"><input name="btnZero" type="Button" value=" 0 " onclick="NumPressed(0)" class="Button"></td>
  49. <td width="50"><input name="btnDecimal" type="Button" value=" . " onclick="Decimal()" class="Button"></td>
  50. <td colspan="4">
  51.  
  52. </td>
  53. <td colspan="5"><input name="btnEquals" type="Button" value=" = " onClick="Operation('=')" class="Button"></td>
  54. </tr>
  55. </table>
  56. </form>
  57. <script LANGUAGE="JavaScript">
  58. var FKeyPad = document.Keypad;
  59. var Accum = 0;
  60. var FlagNewNum = false;
  61. var PendingOp = "";
  62. function NumPressed (Num) {
  63. if (FlagNewNum) {
  64. FKeyPad.ReadOut.value = Num;
  65. FlagNewNum = false;
  66. }
  67. else {
  68. if (FKeyPad.ReadOut.value == "0")
  69. FKeyPad.ReadOut.value = Num;
  70. else
  71. FKeyPad.ReadOut.value += Num;
  72. }
  73. }
  74. function Operation (Op) {
  75. var Readout = FKeyPad.ReadOut.value;
  76. if (FlagNewNum && PendingOp != "=");
  77. else
  78. {
  79. FlagNewNum = true;
  80. if ( '+' == PendingOp )
  81. Accum += parseFloat(Readout);
  82. else if ( '-' == PendingOp )
  83. Accum -= parseFloat(Readout);
  84. else if ( '/' == PendingOp )
  85. Accum /= parseFloat(Readout);
  86. else if ( '*' == PendingOp )
  87. Accum *= parseFloat(Readout);
  88. else
  89. Accum = parseFloat(Readout);
  90. FKeyPad.ReadOut.value = Accum;
  91. PendingOp = Op;
  92. }
  93. }
  94. function Decimal () {
  95. var curReadOut = FKeyPad.ReadOut.value;
  96. if (FlagNewNum) {
  97. curReadOut = "0.";
  98. FlagNewNum = false;
  99. }
  100. else
  101. {
  102. if (curReadOut.indexOf(".") == -1)
  103. curReadOut += ".";
  104. }
  105. FKeyPad.ReadOut.value = curReadOut;
  106. }
  107. function ClearEntry () {
  108. FKeyPad.ReadOut.value = "0";
  109. FlagNewNum = true;
  110. }
  111. function Clear () {
  112. Accum = 0;
  113. PendingOp = "";
  114. ClearEntry();
  115. }
  116. function Neg () {
  117. FKeyPad.ReadOut.value = parseFloat(FKeyPad.ReadOut.value) * -1;
  118. }
  119. function Percent () {
  120. FKeyPad.ReadOut.value = (parseFloat(FKeyPad.ReadOut.value) / 100) * parseFloat(Accum);
  121. }
  122. function hexchange()
  123. {
  124. var hex,dec;
  125. dec = parseFloat(FKeyPad.ReadOut.value);
  126. hex = dec.toString(16);
  127. window.alert("該十進制數轉成十六進制數為:"+ hex);
  128. }
  129. function octchange()
  130. {
  131. var oct,dec;
  132. dec = parseFloat(FKeyPad.ReadOut.value);
  133. oct = dec.toString(8);
  134. window.alert("該十進制數轉成八進制數為:"+ oct);
  135. }
  136. function binchange()
  137. {
  138. var bin,dec;
  139. dec = parseFloat(FKeyPad.ReadOut.value);
  140. bin = dec.toString(2);
  141. window.alert("該十進制數轉成二進制數為:"+ bin);
  142. }
  143. </script> </center>

  144. <p align=center style='text-align:center'>

  145.  </p>
複製代碼

演示

 

臉書網友討論
發表於 2012-3-30 01:05:00 | 顯示全部樓層
支持你一下下。。  

版主招募中

您需要登錄後才可以回帖 登錄 | 註冊 |

本版積分規則



Archiver|手機版|小黑屋|免責聲明|TShopping

GMT+8, 2016-12-9 20:05 , Processed in 0.057358 second(s), 18 queries .

本論壇言論純屬發表者個人意見,與 TShopping綜合論壇 立場無關 如有意見侵犯了您的權益 請寫信聯絡我們。

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回復 返回頂部 返回列表