Dz7js.html 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <title>Document</title>
  8. </head>
  9. <body>
  10. <div>
  11. <input type="number" id="numberOne">
  12. <input type="number" id="numberTwo">
  13. <button id="calc">Рассчитать</button>
  14. <input type="text" value=" " id="result">
  15. </div>
  16. <script>
  17. //Таблица умножения
  18. const table = document.createElement('table');
  19. document.body.append(table);
  20. for (let i = 1; i < 10; i++) {
  21. let tr = document.createElement('tr')
  22. table.append(tr)
  23. for (let a = 1; a < 10; a++) {
  24. let td = document.createElement("td");
  25. tr.append(td);
  26. td.innerText = i * a;
  27. td.style.border = "1px solid black";
  28. }
  29. }
  30. //Подсветить ячейку
  31. // let tdarr = [...table.querySelectorAll('td')]
  32. // tdarr.forEach(tdOn => tdOn.onmousemove = function () {
  33. // this.style.backgroundColor = "green"
  34. // })
  35. // tdarr.forEach(tdOut => tdOut.onmouseout = function () {
  36. // this.style.backgroundColor = "transparent"
  37. // this.parentElement.style.backgroundColor = "transparent"
  38. // })
  39. //Подсветить строку и столбец,
  40. let tdarr = document.querySelectorAll('td')
  41. tdarr.forEach(tdOn => tdOn.onmousemove = function () {
  42. this.style.backgroundColor = "green"
  43. this.parentElement.style.backgroundColor = "green"
  44. let index = this.cellIndex;
  45. let column = document.querySelectorAll("tr")
  46. column.forEach((columns) => columns.children[index].style.backgroundColor = "green");
  47. })
  48. tdarr.forEach(tdOut => tdOut.onmouseout = function () {
  49. this.style.backgroundColor = "transparent"
  50. this.parentElement.style.backgroundColor = "transparent"
  51. let index = this.cellIndex;
  52. let column = document.querySelectorAll("tr")
  53. column.forEach((columns) => columns.children[index].style.backgroundColor = "transparent");
  54. })
  55. //calc
  56. // let number1 = document.getElementById("numberOne")
  57. // let number2 = document.getElementById("numberTwo")
  58. // calc.onclick = function(){
  59. // result.value = ((+numberOne.value) + (+numberTwo.value))
  60. // }
  61. // Calc live
  62. function calc() {
  63. result.value = ((+numberOne.value) + (+numberTwo.value))
  64. }
  65. numberOne.oninput = calc
  66. numberTwo.oninput = calc
  67. </script>
  68. </body>
  69. </html>