TShopping

 找回密碼
 註冊
搜索
查看: 888|回復: 7

[教學] 計算機(2)

[複製鏈接]
發表於 2008-6-1 16:20:16 | 顯示全部樓層 |閱讀模式
 
Push to Facebook Push to Plurk Push to Twitter 

  1. <style type="text/css">
  2. <!--
  3. td { font: 9pt "新細明體"; color: #FFFFFF}
  4. .Button { font: 9pt "新細明體"; color: #FFFFFF; background: #999999; margin: 4px 4px; width: 40px; height: 20px; border-color: #CCCCCC #333333 #333333 #CCCCCC; border-top-width: 2px; border-right-width: 2px; border-bottom-width: 2px; border-left-width: 2px}
  5. .text_input { font: 9pt "Verdana", "Arial", "Helvetica", "sans-serif"; color: #000000; background: #CCCCCC; text-align: right}
  6. a { font: 9pt "新細明體"; color: #FFFFFF}
  7. -->
  8. </style>

  9. <!------- JS計算機開始-------->
  10. <form name="Keypad" action>
  11.  <table border="1" width="249" height="30" cellpadding="0" cellspacing="1" bordercolorlight="#CCCCCC" bordercolordark="#999999" bordercolor="#CCCCCC" bgcolor="#666666">
  12.   <tr>
  13.    <td colspan="4" align="middle"><input name="ReadOut" type="Text" size="30" value="0" width="100%" class="text_input"></td>
  14.    <td width="0"> </td>
  15.    <td width="50"><input name="btnClear" type="Button" value=" C " onclick="Clear()" class="Button"></td>
  16.    <td><input name="btnClearEntry2" type="Button" value=" CE " onClick="ClearEntry()" class="Button"></td>
  17.   </tr>
  18.   <tr>
  19.    <td width="50"><input name="btnSeven" type="Button" value=" 7 " onclick="NumPressed(7)" class="Button"></td>
  20.    <td width="50"><input name="btnEight" type="Button" value=" 8 " onclick="NumPressed(8)" class="Button"></td>
  21.    <td width="50"><input name="btnNine" type="Button" value=" 9 " onclick="NumPressed(9)" class="Button"></td>
  22.    <td width="50"><input name="btnHex" type="Button" value="HEX" onClick="hexchange()" class="Button"></td>
  23.    <td width="0"> </td>
  24.    <td width="50"><input name="btnNeg" type="Button" value=" +/- " onclick="Neg()" class="Button"></td>
  25.    <td><input name="btnPercent" type="Button" value=" % " onClick="Percent()" class="Button"></td>
  26.   </tr>
  27.   <tr>
  28.    <td width="50"><input name="btnFour" type="Button" value=" 4 " onclick="NumPressed(4)" class="Button"></td>
  29.    <td width="50"><input name="btnFive" type="Button" value=" 5 " onclick="NumPressed(5)" class="Button"></td>
  30.    <td width="50"><input name="btnSix" type="Button" value=" 6 " onclick="NumPressed(6)" class="Button"></td>
  31.    <td width="50"><input name="btnClearEntry222" type="Button" value="OCT" onClick="octchange()" class="Button"></td>
  32.    <td width="0"> </td>
  33.    <td align="middle" width="50"><input name="btnPlus" type="Button" value=" + " onclick="Operation('+')" class="Button"></td>
  34.    <td align="middle"><input name="btnMinus" type="Button" value=" -  " onClick="Operation('-')" class="Button"></td>
  35.   </tr>
  36.   <tr>
  37.    <td width="50"><input name="btnOne" type="Button" value=" 1 " onclick="NumPressed(1)" class="Button"></td>
  38.    <td width="50"><input name="btnTwo" type="Button" value=" 2 " onclick="NumPressed(2)" class="Button"></td>
  39.    <td width="50"><input name="btnThree" type="Button" value=" 3 " onclick="NumPressed(3)" class="Button"></td>
  40.    <td width="50"><input name="btnClearEntry23" type="Button" value="BIN" onClick="binchange()" class="Button"></td>
  41.    <td width="0"> </td>
  42.    <td align="middle" width="50"><input name="btnMultiply" type="Button" value=" * " onclick="Operation('*')" class="Button"></td>
  43.    <td align="middle"><input name="btnDivide" type="Button" value=" /  " onClick="Operation('/')" class="Button"></td>
  44.   </tr>
  45.   <tr>
  46.    <td width="50"><input name="btnZero" type="Button" value=" 0 " onclick="NumPressed(0)" class="Button"></td>
  47.    <td width="50"><input name="btnDecimal" type="Button" value="  . " onclick="Decimal()" class="Button"></td>
  48.    <td colspan="4">
  49.     <div align="center">
  50.      <a href=http://www.moninet.com.tw/ target=_blank>摩尼網</a> 
  51.     </div> 
  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> 
  144. <!------- JS計算機結束-------->
  145.  
複製代碼

 

臉書網友討論
發表於 2011-7-21 00:55:59 | 顯示全部樓層
我等你喲!  

版主招募中

發表於 2011-7-21 01:00:40 | 顯示全部樓層
幫你頂,人還是厚道點好  


發表於 2012-2-1 00:46:54 | 顯示全部樓層
拿分走人呵呵,樓下繼續!


發表於 2012-2-1 01:00:13 | 顯示全部樓層
自己知道了  


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

本版積分規則



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

GMT+8, 2016-12-3 12:05 , Processed in 0.056756 second(s), 19 queries .

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

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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