ASCII码 ASCII码

.使用制作简版计算器与.九九乘法表

发布于:2022-05-20 18:05:45  栏目:技术文档

1.简易计算器

  1. <body>
  2. <form action="" method="post">
  3. <input type="number" id="num1" />
  4. <select id="ysf">
  5. <option value="+" id="+">+</option>
  6. <option value="-" id="-">-</option>
  7. <option value="*" id="*">*</option>
  8. <option value="/" id="/">/</option>
  9. <option value="%" id="%">%</option>
  10. </select>
  11. <input type="number" id="num2" />
  12. <input type="button" value="计算" id="btn" />
  13. </form>
  14. <p id="res"></p>
  15. <script>
  16. document.getElementById("btn").onclick = function () {
  17. var num1 = document.getElementById("num1").value;
  18. var num2 = document.getElementById("num2").value;
  19. var ysf = document.getElementById("ysf").value;
  20. document.getElementById("res").innerHTML = num1 + "---" + num2 + "---" + ysf;
  21. var res = document.getElementById("res");
  22. var fh = ysf;
  23. switch (ysf) {
  24. case document.getElementById("+").value:
  25. res.innerHTML = num1 + ysf + num2 + "=" + (num1 * 1 + num2 * 1);
  26. console.log(ysf);
  27. break;
  28. case document.getElementById("-").value:
  29. res.innerHTML = num1 + ysf + num2 + "=" + (num1 * 1 - num2 * 1);
  30. console.log(ysf);
  31. break;
  32. case document.getElementById("*").value:
  33. res.innerHTML = num1 + ysf + num2 + "=" + num1 * 1 * num2 * 1;
  34. break;
  35. case document.getElementById("/").value:
  36. res.innerHTML = num1 + ysf + num2 + "=" + num1 / num2;
  37. break;
  38. case document.getElementById("%").value:
  39. res.innerHTML = num1 + ysf + num2 + "=" + (num1 % num2);
  40. break;
  41. }
  42. };
  43. document.write('<table border="1" width="800px" align=center >');
  44. for (var hang = 1; hang <= 9; hang++) {
  45. document.write("<tr>");
  46. for (var lie = 1; lie <= hang; lie++) {
  47. document.write("<td>" + lie + "*" + hang + "=" + hang * lie + "</td> ");
  48. }
  49. document.write("</tr>");
  50. }
  51. </script>

成品图:

2.九九乘法表

  1. <script>
  2. document.write('<table border="1" width="800px" align=center >');
  3. for (var hang = 1; hang <= 9; hang++) {
  4. document.write("<tr>");
  5. for (var lie = 1; lie <= hang; lie++) {
  6. document.write("<td>" + lie + "*" + hang + "=" + hang * lie + "</td> ");
  7. }
  8. document.write("</tr>");
  9. }
  10. </script>

附成品图:

相关推荐
阅读 +