JS實現的計算機

來源:互聯網
上載者:User

js實現的計算機,如下代碼:

  1. <%@ Page Language="C#" AutoEventWireup="true" CodeFile="calc.aspx.cs" Inherits="calc" %> 
  2.  
  3. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
  4.  
  5. <html xmlns="http://www.w3.org/1999/xhtml"> 
  6. <head runat="server"> 
  7. <title>JS計算機 - www.cxybl.com</title> 
  8. <style type="text/css"> 
  9. .style1 
  10. { 
  11. width: 22%; 
  12. } 
  13. #Button1 
  14. { 
  15. height: 41px; 
  16. width: 60px; 
  17. } 
  18. #Button2 
  19. { 
  20. height: 41px; 
  21. width: 60px; 
  22. } 
  23. #Button3 
  24. { 
  25. height: 41px; 
  26. width: 63px; 
  27. } 
  28. #Button4 
  29. { 
  30. height: 41px; 
  31. width: 64px; 
  32. } 
  33. #Button5 
  34. { 
  35. height: 41px; 
  36. width: 57px; 
  37. } 
  38. #Button6 
  39. { 
  40. height: 41px; 
  41. width: 61px; 
  42. } 
  43. #Button7 
  44. { 
  45. height: 41px; 
  46. width: 64px; 
  47. } 
  48. #Button8 
  49. { 
  50. height: 41px; 
  51. width: 64px; 
  52. } 
  53. #Button9 
  54. { 
  55. height: 41px; 
  56. width: 62px; 
  57. } 
  58. #Button10 
  59. { 
  60. height: 41px; 
  61. width: 63px; 
  62. } 
  63. #Button11 
  64. { 
  65. height: 41px; 
  66. width: 67px; 
  67. } 
  68. #Button12 
  69. { 
  70. height: 41px; 
  71. width: 64px; 
  72. } 
  73. #Button13 
  74. { 
  75. height: 41px; 
  76. width: 61px; 
  77. } 
  78. #Button14 
  79. { 
  80. height: 41px; 
  81. width: 59px; 
  82. } 
  83. #Button15 
  84. { 
  85. height: 41px; 
  86. width: 67px; 
  87. } 
  88. #Button16 
  89. { 
  90. height: 41px; 
  91. width: 65px; 
  92. } 
  93. #Text1 
  94. { 
  95. width: 258px; 
  96. height: 38px; 
  97. } 
  98. .style2 
  99. { 
  100. width: 62px; 
  101. } 
  102. #Button17 
  103. { 
  104. height: 41px; 
  105. width: 61px; 
  106. } 
  107. #Button18 
  108. { 
  109. height: 41px; 
  110. width: 63px; 
  111. } 
  112. #Button19 
  113. { 
  114. height: 41px; 
  115. width: 67px; 
  116. } 
  117. #Button20 
  118. { 
  119. height: 41px; 
  120. width: 62px; 
  121. } 
  122. </style> 
  123. <script language="javascript" type="text/javascript"> 
  124. var num; 
  125. function btntext(num) { 
  126. document.getElementById('Text1').value += document.getElementById(num).value; 
  127. }//給文字框賦值 
  128. function ev() { 
  129. document.getElementById('Text1').value = eval(document.getElementById('Text1').value); 
  130. } //計算文字框內的運算式 
  131. function clear() { 
  132. document.getElementById('Text1').value =0; 
  133. } //吧文字框內的內容清0 
  134. function SQRT() { 
  135. var disp = document.getElementById('Text1'); 
  136. disp.value = Math.sqrt(disp.value); 
  137.  
  138. }//開根號 
  139.  
  140. function Pow() { 
  141. var disp = document.getElementById('Text1'); 
  142. disp.value = Math.pow(disp.value, 2); 
  143. }//平方 
  144. function del() { 
  145. var disp = document.getElementById('Text1'); 
  146. dispdisp.value = disp.value.substring(0, disp.value.length - 1) 
  147. } //刪除 
  148. </script> 
  149. </head> 
  150. <body> 
  151. <form id="form1" runat="server"> 
  152. <div> 
  153. <table align="center" class="style1" 
  154. style="background-color: #C0C0C0; height: 291px;"> 
  155. <tr> 
  156. <td colspan="4" style="background-color: #00FFFF; text-align: center;"> 
  157. <input id="Text1" type="text" /></td> 
  158. </tr> 
  159. <tr> 
  160. <td style="background-color: #00FFFF"> 
  161. <input id="+" type="button" value="+" onclick="btntext('+')"/></td> 
  162. <td style="background-color: #00FFFF"> 
  163. <input id="1" type="button" value="1" name='1' onclick="btntext('1')" /></td> 
  164. <td style="background-color: #00FFFF"> 
  165. <input id="2" type="button" value="2" onclick="btntext('2')"/></td> 
  166. <td class="style2" style="background-color: #00FFFF"> 
  167. <input id="3" type="button" value="3" onclick="btntext('3')"/></td> 
  168. </tr> 
  169. <tr> 
  170. <td style="background-color: #00FFFF"> 
  171. <input id="-" type="button" value="-" onclick="btntext('-')"/></td> 
  172. <td style="background-color: #00FFFF"> 
  173. <input id="4" type="button" value="4" onclick="btntext('4')"/></td> 
  174. <td style="background-color: #00FFFF"> 
  175. <input id="5" type="button" value="5" onclick="btntext('5')"/></td> 
  176. <td class="style2" style="background-color: #00FFFF"> 
  177. <input id="6" type="button" value="6" onclick="btntext('6')"/></td> 
  178. </tr> 
  179. <tr> 
  180. <td style="background-color: #00FFFF"> 
  181. <input id="*" type="button" value="*" onclick="btntext('*')"/></td> 
  182. <td style="background-color: #00FFFF"> 
  183. <input id="7" type="button" value="7" onclick="btntext('7')"/></td> 
  184. <td style="background-color: #00FFFF"> 
  185. <input id="8" type="button" value="8" onclick="btntext('8')"/></td> 
  186. <td class="style2" style="background-color: #00FFFF"> 
  187. <input id="9" type="button" value="9" onclick="btntext('9')"/></td> 
  188. </tr> 
  189. <tr> 
  190. <td style="background-color: #00FFFF"> 
  191. <input id="/" type="button" value="/" onclick="btntext('/')"/></td> 
  192. <td style="background-color: #00FFFF"> 
  193. <input id="0" type="button" value="0" onclick="btntext('0')"/></td> 
  194. <td style="background-color: #00FFFF"> 
  195. <input id="." type="button" value="." style="font-weight: bold" onclick="btntext('.')"/></td> 
  196. <td class="style2" style="background-color: #00FFFF"> 
  197. <input id="Button16" type="button" value="=" onclick="ev()"/></td> 
  198. </tr> 
  199. <tr> 
  200. <td style="background-color: #00FFFF"> 
  201. <input id='根號' type="button" value="√" onclick="SQRT()"/></td> 
  202. <td style="background-color: #00FFFF"> 
  203. <input id="平方" type="button" value="²" onclick="Pow()"/></td> 
  204. <td style="background-color: #00FFFF"> 
  205. <input id="Button19" type="button" value="C" onclick="clear()"/></td> 
  206. <td class="style2" style="background-color: #00FFFF"> 
  207. <input id="Button20" type="button" value="←" onclick="del()"/></td> 
  208. </tr> 
  209. </table> 
  210. </div> 
  211. </form> 
  212. </body> 
  213. </html> 


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.