script.js 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. // ----------------------------------------------Таблица умножения------------------------------------------------------------------
  2. let task1 = document.createElement("div");
  3. document.body.append(task1);
  4. task1.innerText = "Таблица умножения";
  5. // task1.style = "border: 2px solid; display: flex; justifyContent: center; alignItems: center; textAlign: center; margin: 15px 0"
  6. task1.style = "border: 2px solid; text-align: center; margin: 15px 0"
  7. let table = document.createElement("table");
  8. table.setAttribute("border", "1");
  9. document.body.append(table);
  10. table.setAttribute("align", "center");
  11. for (let y = 0; y < 10; y++) {
  12. let tr = document.createElement("tr");
  13. table.append(tr);
  14. for (let x = 0; x < 10; x++) {
  15. let td = document.createElement("td");
  16. tr.append(td);
  17. let temp = x * y;
  18. if (x === 0) temp = y;
  19. else if (y === 0) temp = x;
  20. td.innerText = temp;
  21. // td.innerHTML(x * y);
  22. td.style.width = "50px";
  23. td.style.height = "25px";
  24. td.style.textAlign = "center";
  25. // -----------------Подсветить ячейку--------------------
  26. td.onmousemove = function () {
  27. this.style.background = "yellow";
  28. }
  29. td.onmouseout = function () {
  30. this.style.background = "none";
  31. }
  32. }
  33. }
  34. // ____Тестовый вариант, чтобы разобраться_____
  35. // document.write("<table width=60% border=1 cellspacing=0 cellpadding=4>")
  36. // // document.write("<table border=1 >")
  37. // for (i = 0; i < 10; i++) {
  38. // if(i === 0) i=1
  39. // document.write("<tr>");
  40. // for (j = 0; j < 10; j++) {
  41. // if(i === 0) ++j
  42. // document.write("<td>" + (j * i) + "</td>");
  43. // }
  44. // document.write("</tr>");
  45. // }
  46. // document.write("</table>")
  47. // ---------------------------------------------Подсветить строку и столбец------------------------------------------------------------------
  48. let task2 = document.createElement("div");
  49. document.body.append(task2);
  50. task2.innerText = "Подсветить строку и столбец";
  51. task2.style = "border: 2px solid; text-align: center; margin: 15px 0"
  52. function light() {
  53. let table = document.createElement("table");
  54. table.setAttribute("border", "1");
  55. document.body.append(table);
  56. table.setAttribute("align", "center");
  57. for (let y = 0; y < 10; y++) {
  58. let tr = document.createElement("tr");
  59. table.append(tr);
  60. for (let x = 0; x < 10; x++) {
  61. let td = document.createElement("td");
  62. tr.append(td);
  63. let temp = x * y;
  64. if (x === 0) temp = y;
  65. else if (y === 0) temp = x;
  66. td.innerText = temp;
  67. // td.innerHTML(x * y);
  68. td.style.width = "50px";
  69. td.style.height = "25px";
  70. td.style.textAlign = "center";
  71. td.onmousemove = function () {
  72. for (let item of this.parentElement.children) {
  73. item.style.background = "yellowgreen";
  74. }
  75. for (let item of this.parentElement.parentElement.children) {
  76. for (let item2 of item.children) {
  77. if (item2.cellIndex === this.cellIndex) {
  78. item2.style.background = "yellowgreen";
  79. }
  80. }
  81. }
  82. }
  83. td.onmouseout = function () {
  84. for (let item of this.parentElement.children) {
  85. item.style.background = "none";
  86. }
  87. for (let item of this.parentElement.parentElement.children) {
  88. for (let item2 of item.children) {
  89. if (item2.cellIndex === this.cellIndex) {
  90. item2.style.background = "none";
  91. }
  92. }
  93. }
  94. }
  95. }
  96. }
  97. }
  98. light();
  99. // _______________________Выбор ячейки_____________________________
  100. let task3 = document.createElement("div");
  101. document.body.append(task3);
  102. task3.innerText = "Выбор ячейки (сделал для практики)";
  103. task3.style = "border: 2px solid; text-align: center; margin: 15px 0"
  104. table = document.createElement("table");
  105. table.setAttribute("border", "1");
  106. document.body.append(table);
  107. table.setAttribute("align", "center");
  108. for (let y = 0; y < 10; y++) {
  109. let tr = document.createElement("tr");
  110. table.append(tr);
  111. for (let x = 0; x < 10; x++) {
  112. let td = document.createElement("td");
  113. tr.append(td);
  114. let temp = x * y;
  115. if (x === 0) temp = y;
  116. else if (y === 0) temp = x;
  117. td.innerText = temp;
  118. td.style.width = "50px";
  119. td.style.height = "25px";
  120. td.style.textAlign = "center";
  121. let flag = false;
  122. td.onclick = function () {
  123. if (!flag) {
  124. this.style.background = "blue";
  125. this.style.color = "#d1e819"
  126. } else {
  127. this.style.background = "none";
  128. this.style.color = "black"
  129. }
  130. flag = !flag;
  131. }
  132. }
  133. }
  134. // ----------------------------------------------Calc------------------------------------------------------------------
  135. let task4 = document.createElement("div");
  136. document.body.append(task4);
  137. task4.innerText = "Calc";
  138. task4.style = "border: 2px solid; text-align: center; margin: 15px 0"
  139. let num1 = document.createElement("input");
  140. let num2 = document.createElement("input");
  141. let result = document.createElement("div");
  142. let calc = document.createElement("button");
  143. let check = document.createElement("input");
  144. let wrapper = document.createElement("div")
  145. num1.setAttribute("id", "1");
  146. num1.setAttribute("type", "number");
  147. num1.setAttribute("placeholder", "0");
  148. num2.setAttribute("id", "2");
  149. num2.setAttribute("type", "number");
  150. num2.setAttribute("placeholder", "0");
  151. result.setAttribute("id", "res");
  152. calc.setAttribute("id", "button");
  153. check.setAttribute("id", "checkbox");
  154. check.setAttribute("type", "checkbox");
  155. document.body.append(wrapper);
  156. wrapper.append(num1);
  157. wrapper.append(num2);
  158. wrapper.append(result);
  159. wrapper.append(calc);
  160. wrapper.append(check);
  161. // document.write("shc");
  162. wrapper.append('Automation Calculation');
  163. wrapper.style = "display: flex; justify-content: space-around";
  164. // document.body.insertAdjacentHTML("beforeEnd", 'abrakadabra')
  165. // calc.style = "height: 50px; width: 150px; background: #6290d0";
  166. calc.innerHTML = "Calculate"
  167. result.style = "height: 50px; width: 150px; background: #fff; border: 2px solid";
  168. calc.onclick = () => {
  169. // result.innerText = num1.value + num2.value;
  170. result.innerText = (+num1.value) + (+num2.value);
  171. }
  172. check.oninput = () => {
  173. if(check.checked) {
  174. calc.setAttribute("disabled", "disabled");
  175. num1.oninput = num2.oninput = calc.onclick;
  176. calc.onclick();
  177. }
  178. else {
  179. calc.removeAttribute("disabled");
  180. num1.oninput = num2.oninput = null;
  181. }
  182. }