JS implementation of the calculator

Source: Internet
Author: User
Tags pow square root

JS implementation of the calculator, the following code:

 
 
  1. <%@ Page language= "C #" autoeventwireup= "true" codefile= "Calc.aspx.cs" inherits= "Calc"%>
  2. <! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
  3. <title>js Calculator-Www.cxybl.com</title>
  4. <style type= "Text/css" >
  5. . style1
  6. {
  7. width:22%;
  8. }
  9. #Button1
  10. {
  11. height:41px;
  12. width:60px;
  13. }
  14. #Button2
  15. {
  16. height:41px;
  17. width:60px;
  18. }
  19. #Button3
  20. {
  21. height:41px;
  22. width:63px;
  23. }
  24. #Button4
  25. {
  26. height:41px;
  27. width:64px;
  28. }
  29. #Button5
  30. {
  31. height:41px;
  32. width:57px;
  33. }
  34. #Button6
  35. {
  36. height:41px;
  37. width:61px;
  38. }
  39. #Button7
  40. {
  41. height:41px;
  42. width:64px;
  43. }
  44. #Button8
  45. {
  46. height:41px;
  47. width:64px;
  48. }
  49. #Button9
  50. {
  51. height:41px;
  52. width:62px;
  53. }
  54. #Button10
  55. {
  56. height:41px;
  57. width:63px;
  58. }
  59. #Button11
  60. {
  61. height:41px;
  62. width:67px;
  63. }
  64. #Button12
  65. {
  66. height:41px;
  67. width:64px;
  68. }
  69. #Button13
  70. {
  71. height:41px;
  72. width:61px;
  73. }
  74. #Button14
  75. {
  76. height:41px;
  77. width:59px;
  78. }
  79. #Button15
  80. {
  81. height:41px;
  82. width:67px;
  83. }
  84. #Button16
  85. {
  86. height:41px;
  87. width:65px;
  88. }
  89. #Text1
  90. {
  91. width:258px;
  92. height:38px;
  93. }
  94. . style2
  95. {
  96. width:62px;
  97. }
  98. #Button17
  99. {
  100. height:41px;
  101. width:61px;
  102. }
  103. #Button18
  104. {
  105. height:41px;
  106. width:63px;
  107. }
  108. #Button19
  109. {
  110. height:41px;
  111. width:67px;
  112. }
  113. #Button20
  114. {
  115. height:41px;
  116. width:62px;
  117. }
  118. </style>
  119. <script language= "javascript" type= "Text/javascript" >
  120. var num;
  121. function Btntext (num) {
  122. document.getElementById (' Text1 '). Value + = document.getElementById (num). value;
  123. }//a text box to assign a value
  124. function ev () {
  125. document.getElementById (' Text1 '). Value = eval (document.getElementById (' Text1 '). Value);
  126. }//Calculate the expression within the text box
  127. function Clear () {
  128. document.getElementById (' Text1 '). Value = 0;
  129. //bar contents of text box clear 0
  130. function SQRT () {
  131. var disp = document.getElementById (' Text1 ');
  132. Disp.value = Math.sqrt (Disp.value);
  133. }//Open Radical Root
  134. function Pow () {
  135. var disp = document.getElementById (' Text1 ');
  136. Disp.value = Math.pow (Disp.value, 2);
  137. }//Square
  138. Function del () {
  139. var disp = document.getElementById (' Text1 ');
  140. Dispdisp.value = disp.value.substring (0, Disp.value.length-1)
  141. }//Delete
  142. </script>
  143. <body>
  144. <form id= "Form1" runat= "Server" >
  145. <div>
  146. <table align= "center" class= "Style1"
  147. Style= "Background-color: #C0C0C0; height:291px; " >
  148. <tr>
  149. <TD colspan= "4" style= "Background-color: #00FFFF; Text-align:center; " >
  150. <input id= "Text1" type= "text"/></td>
  151. </tr>
  152. <tr>
  153. <TD style= "Background-color: #00FFFF" >
  154. <input id= "+" type= "button" value= "+" onclick= "btntext (' + ')"/></td>
  155. <TD style= "Background-color: #00FFFF" >
  156. <input id= "1" type= "button" value= "1" name= ' 1 ' onclick= "Btntext (' 1 ')"/></td>
  157. <TD style= "Background-color: #00FFFF" >
  158. <input id= "2" type= "button" value= "2" onclick= "Btntext (' 2 ')"/></td>
  159. <TD class= "Style2" style= "Background-color: #00FFFF" >
  160. <input id= "3" type= "button" value= "3" onclick= "Btntext (' 3 ')"/></td>
  161. </tr>
  162. <tr>
  163. <TD style= "Background-color: #00FFFF" >
  164. <input id= "-" type= "button" value= "-" onclick= "Btntext ('-')"/></td>
  165. <TD style= "Background-color: #00FFFF" >
  166. <input id= "4" type= "button" value= "4" onclick= "Btntext (' 4 ')"/></td>
  167. <TD style= "Background-color: #00FFFF" >
  168. <input id= "5" type= "button" value= "5" onclick= "Btntext (' 5 ')"/></td>
  169. <TD class= "Style2" style= "Background-color: #00FFFF" >
  170. <input id= "6" type= "button" value= "6" onclick= "Btntext (' 6 ')"/></td>
  171. </tr>
  172. <tr>
  173. <TD style= "Background-color: #00FFFF" >
  174. <input id= "*" type= "button" value= "*" onclick= "btntext (' * ')"/></td>
  175. <TD style= "Background-color: #00FFFF" >
  176. <input id= "7" type= "button" value= "7" onclick= "Btntext (' 7 ')"/></td>
  177. <TD style= "Background-color: #00FFFF" >
  178. <input id= "8" type= "button" value= "8" onclick= "Btntext (' 8 ')"/></td>
  179. <TD class= "Style2" style= "Background-color: #00FFFF" >
  180. <input id= "9" type= "button" value= "9" onclick= "Btntext (' 9 ')"/></td>
  181. </tr>
  182. <tr>
  183. <TD style= "Background-color: #00FFFF" >
  184. <input id= "/" type= "button" value= "/" onclick= "btntext ('/')"/></td>
  185. <TD style= "Background-color: #00FFFF" >
  186. <input id= "0" type= "button" value= "0" onclick= "Btntext (' 0 ')"/></td>
  187. <TD style= "Background-color: #00FFFF" >
  188. <input id= "." Type= "button" value= "." Style= "Font-weight:bold" onclick= "Btntext ('. ') /></td>
  189. <TD class= "Style2" style= "Background-color: #00FFFF" >
  190. <input id= "Button16" type= "button" value= "=" onclick= "ev ()"/></td>
  191. </tr>
  192. <tr>
  193. <TD style= "Background-color: #00FFFF" >
  194. <input id= ' square root ' type= ' button ' value= ' √ ' onclick= ' SQRT () '/></td>
  195. <TD style= "Background-color: #00FFFF" >
  196. <input id= "Square" type= "button" value= "²" onclick= "Pow ()"/></td>
  197. <TD style= "Background-color: #00FFFF" >
  198. <input id= "Button19" type= "button" value= "C" onclick= "Clear ()"/></td>
  199. <TD class= "Style2" style= "Background-color: #00FFFF" >
  200. <input id= "Button20" type= "button" value= "←" onclick= "del ()"/></td>
  201. </tr>
  202. </table>
  203. </div>
  204. </form>
  205. </body>


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.