• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

JS实现的计算器_js

javascript 搞代码 7年前 (2018-06-13) 172次浏览 已收录 0个评论

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. width: 22%; 
  11. #Button1 
  12. height: 41px; 
  13. width: 60px; 
  14. #Button2 
  15. height: 41px; 
  16. width: 60px; 
  17. #Button3 
  18. height: 41px; 
  19. width: 63px; 
  20. #Button4 
  21. height: 41px; 
  22. width: 64px; 
  23. #Button5 
  24. height: 41px; 
  25. width: 57px; 
  26. #Button6 
  27. height: 41px; 
  28. width: 61px; 
  29. #Button7 
  30. height: 41px; 
  31. width: 64px; 
  32. #Button8 
  33. height: 41px; 
  34. width: 64px; 
  35. #Button9 
  36. height: 41px; 
  37. width: 62px; 
  38. #Button10 
  39. height: 41px; 
  40. width: 63px; 
  41. #Button11 
  42. height: 41px; 
  43. width: 67px; 
  44. #Button12 
  45. height: 41px; 
  46. width: 64px; 
  47. #Button13 
  48. height: 41px; 
  49. width: 61px; 
  50. #Button14 
  51. height: 41px; 
  52. width: 59px; 
  53. #Button15 
  54. height: 41px; 
  55. width: 67px; 
  56. #Button16 
  57. height: 41px; 
  58. width: 65px; 
  59. #Text1 
  60. width: 258px; 
  61. height: 38px; 
  62. .style2 
  63. width: 62px; 
  64. #Button17 
  65. height: 41px; 
  66. width: 61px; 
  67. #Button18 
  68. height: 41px; 
  69. width: 63px; 
  70. #Button19 
  71. height: 41px; 
  72. width: 67px; 
  73. #Button20 
  74. height: 41px; 
  75. width: 62px; 
  76. </style> 
  77. <script language="javascript" type="text/javascript"> 
  78. var num; 
  79. function btntext(num) { 
  80. document.getElementById('Text1').value += document.getElementById(num).value; 
  81. }//给文本框赋值 
  82. function ev() { 
  83. document.getElementById('Text1').value = eval(document.getElementById('Text1').value); 
  84. } //计算文本框内的表达式 
  85. function clear() { 
  86. document.getElementById('Text1').value =0
  87. } //吧文本框内的内容清0 
  88. function SQRT() { 
  89. var disp = document.getElementById('Text1'); 
  90. disp.value = Math.sqrt(disp.value); 
  91.  
  92. }//开根号 
  93.  
  94. function Pow() { 
  95. var disp = document.getElementById('Text1'); 
  96. disp.value = Math.pow(disp.value, 2); 
  97. }//平方 
  98. function del() { 
  99. var disp = document.getElementById('Text1'); 
  100. dispdisp.value = disp.value.substring(0, disp.value.length - 1) 
  101. } //删除 
  102. </script> 
  103. </head> 
  104. <body> 
  105. <form id="form1" runat="server"> 
  106. <div> 
  107. <table align="center" class="style1" 
  108. style="background-color: #C0C0C0; height: 291px;"> 
  109. <tr> 
  110. <td colspan="4" style="background-color: #00FFFF; text-align: center;"> 
  111. <input id="Text1" type="text" /></td> 
  112. </tr> 
  113. <tr> 
  114. <td style="background-color: #00FFFF"> 
  115. <input id="+" type="button" value="+" onclick="btntext('+')"/></td> 
  116. <td style="background-color: #00FFFF"> 
  117. <input id="1" type="button" value="1" name='1' onclick="btntext('1')" /></td> 
  118. <td style="background-color: #00FFFF"> 
  119. <input id="2" type="button" value="2" onclick="btntext('2')"/></td> 
  120. <td class="style2" style="background-color: #00FFFF"> 
  121. <input id="3" type="button" value="3" onclick="btntext('3')"/></td> 
  122. </tr> 
  123. <tr> 
  124. <td style="background-color: #00FFFF"> 
  125. <input id="-" type="button" value="-" onclick="btntext('-')"/></td> 
  126. <td style="background-color: #00FFFF"> 
  127. <input id="4" type="button" value="4" onclick="btntext('4')"/></td> 
  128. <td style="background-color: #00FFFF"> 
  129. <input id="5" type="button" value="5" onclick="btntext('5')"/></td> 
  130. <td class="style2" style="background-color: #00FFFF"> 
  131. <input id="6" type="button" value="6" onclick="btntext('6')"/></td> 
  132. </tr> 
  133. <tr> 
  134. <td style="background-color: #00FFFF"> 
  135. <input id="*" type="button" value="*" onclick="btntext('*')"/></td> 
  136. <td style="background-color: #00FFFF"> 
  137. <input id="7" type="button" value="7" onclick="btntext('7')"/></td> 
  138. <td style="background-color: #00FFFF"> 
  139. <input id="8" type="button" value="8" onclick="btntext('8')"/></td> 
  140. <td class="style2" style="background-color: #00FFFF"> 
  141. <input id="9" type="button" value="9" onclick="btntext('9')"/></td> 
  142. </tr> 
  143. <tr> 
  144. <td style="background-color: #00FFFF"> 
  145. <input id="/" type="button" value="/" onclick="btntext('/')"/></td> 
  146. <td style="background-color: #00FFFF"> 
  147. <input id="0" type="button" value="0" onclick="btntext('0')"/></td> 
  148. <td style="background-color: #00FFFF"> 
  149. <input id="." type="button" value="." style="font-weight: bold" onclick="btntext('.')"/></td> 
  150. <td class="style2" style="background-color: #00FFFF"> 
  151. <input id="Button16" type="button" value="=" onclick="ev()"/></td> 
  152. </tr> 
  153. <tr> 
  154. <td style="background-color: #00FFFF"> 
  155. <input id='根号' type="button" value="√" onclick="SQRT()"/></td> 
  156. <td style="background-color: #00FFFF"> 
  157. <input id="平方" type="button" value="²" onclick="Pow()"/></td> 
  158. <td style="background-color: #00FFFF"> 
  159. <input id="Button19" type="button" value="C" onclick="clear()"/></td> 
  160. <td class="style2" style="background-color: #00FFFF"> 
  161. <input id="Button20" type="button" value="←" onclick="del()"/></td> 
  162. </tr> 
  163. </table> 
  164. </div> 
  165. </form> 
  166. </body> 
  167. </html> 

欢迎大家阅读《JS实现的计算器_js,跪求各位点评,若觉得好的话请收藏本文,by 搞代码


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:JS实现的计算器_js
喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址