当前位置:   article > 正文

web实现简单计算器_web计算器

web计算器

  1. <html>
  2. <head><title>简单计算器</title>
  3. <style>
  4. .b1{
  5. width:50px;
  6. height:35px;
  7. margin-top:10px;
  8. background-color:#99FFFF;
  9. }
  10. .screen{
  11. width:215px;
  12. height:35px;
  13. text-align: right;
  14. padding-right:10px;
  15. font-size:20px;
  16. background-color:#99FFFF;
  17. }
  18. html{
  19. padding:150px 550px 100px 550px;
  20. background-color:lightgrey;
  21. }
  22. </style>
  23. <script>
  24. function jsj(num){
  25. document.getElementById("result").value+=document.getElementById(num).value;
  26. }
  27. function eva() {
  28. //计算输入结果
  29. document.getElementById("result").value = eval(document.getElementById("result").value);
  30. }
  31. function tuiGe() {
  32. //退格
  33. var arr = document.getElementById("result");
  34. arr.value = arr.value.substring(0, arr.value.length - 1);
  35. }
  36. </script>
  37. </head>
  38. <body>
  39. <div id="screen"><input type="text" name="result" id="result" class="screen" placeholder="请输入计算公式"/></div>
  40. <!-- <div id="buttonArea"> -->
  41. <div>
  42. <input type="button" name="b1" value="1" id="1" class="b1" onclick="jsj(this.id)"/>
  43. <input type="button" name="b2" value="2" id="2" class="b1" onclick="jsj(this.id)"/>
  44. <input type="button" name="b3" value="3" id="3" class="b1" onclick="jsj(this.id)"/>
  45. <input type="button" name="//" value="/" id="/" class="b1" onclick="jsj(this.id)"/><br/>
  46. </div>
  47. <div>
  48. <input type="button" name="b4" value="4" id="4" class="b1" onclick="jsj(this.id)"/>
  49. <input type="button" name="b5" value="5" id="5" class="b1" onclick="jsj(this.id)"/>
  50. <input type="button" name="b6" value="6" id="6" class="b1" onclick="jsj(this.id)"/>
  51. <input type="button" name=".." value="." id="." class="b1" onclick="jsj(this.id)"/><br/>
  52. </div>
  53. <div>
  54. <input type="button" name="b7" value="7" id="7" class="b1" onclick="jsj(this.id)"/>
  55. <input type="button" name="b8" value="8" id="8" class="b1" onclick="jsj(this.id)"/>
  56. <input type="button" name="b9" value="9" id="9" class="b1" onclick="jsj(this.id)"/>
  57. <input type="button" name="plus" value="删除" id="/" class="b1" onclick="tuiGe()"/><br/>
  58. </div>
  59. <div>
  60. <input type="button" name="plus" value="+" id="+" class="b1" onclick="jsj(this.id)"/>
  61. <input type="button" name="plus" value="-" id="-" class="b1" onclick="jsj(this.id)"/>
  62. <input type="button" name="plus" value="*" id="*" class="b1" onclick="jsj(this.id)"/>
  63. <input type="button" name="total" value="=" id="t" class="b1" onclick="eva()"/>
  64. </body>
  65. </html>

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/不正经/article/detail/190808
推荐阅读
相关标签
  

闽ICP备14008679号