main.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. // // Таблица умножения + Подсветить ячейку
  2. // let table = document.createElement('table');
  3. // for (let i = 1; i < 10; i++) {
  4. // let row = document.createElement('tr')
  5. // for (let j = 1; j < 10; j++) {
  6. // let td = document.createElement('td')
  7. // td.onmouseover = function () {
  8. // this.style.backgroundColor = 'red'
  9. // }
  10. // td.onmouseout = function () {
  11. // i % 2 !== 0 ? this.style.backgroundColor = '#e9e9e9' : this.style.backgroundColor = 'white'
  12. // }
  13. // if (i % 2 !== 0) { td.style.backgroundColor = '#e9e9e9' }
  14. // td.innerText = j * i
  15. // td.style.border = '1px solid #d3d3d3'
  16. // td.style.padding = '10px'
  17. // td.style.fontSize = '20px'
  18. // td.style.textAlign = 'center'
  19. // row.appendChild(td)
  20. // }
  21. // table.appendChild(row)
  22. // }
  23. // document.body.appendChild(table)
  24. // Подсветить строку и столбец
  25. let table = document.getElementById('table');
  26. for (let i = 1; i < 10; i++) {
  27. let row = document.createElement('tr')
  28. for (let j = 1; j < 10; j++) {
  29. let td = document.createElement('td')
  30. td.onmouseover = function () {
  31. this.parentElement.style.backgroundColor = 'yellow'
  32. let index = this.cellIndex;
  33. let col = document.querySelectorAll('#table > tr');
  34. col.forEach((row) => row.children[index].style.backgroundColor = 'yellow');
  35. this.style.backgroundColor = 'red';
  36. }
  37. td.onmouseout = function () {
  38. this.style.backgroundColor = 'white'
  39. this.parentElement.style.backgroundColor = ''
  40. let index = this.cellIndex;
  41. let col = document.querySelectorAll('#table > tr');
  42. col.forEach((row) => row.children[index].style.backgroundColor = '');
  43. }
  44. td.innerText = j * i
  45. td.style.border = '1px solid #d3d3d3'
  46. td.style.padding = '10px'
  47. td.style.fontSize = '20px'
  48. td.style.textAlign = 'center'
  49. row.appendChild(td)
  50. }
  51. table.appendChild(row)
  52. }
  53. document.body.appendChild(table)
  54. let secondtable = document.getElementById('table1');
  55. for (let i = 1; i < 10; i++) {
  56. let row = document.createElement('tr')
  57. for (let j = 1; j < 10; j++) {
  58. let td = document.createElement('td')
  59. td.onmouseover = function () {
  60. this.parentElement.style.backgroundColor = 'yellow'
  61. let index = this.cellIndex;
  62. let col = document.querySelectorAll('#table1 > tr');
  63. col.forEach((row) => row.children[index].style.backgroundColor = 'yellow');
  64. this.style.backgroundColor = 'red';
  65. }
  66. td.onmouseout = function () {
  67. this.style.backgroundColor = 'white'
  68. this.parentElement.style.backgroundColor = ''
  69. let index = this.cellIndex;
  70. let col = document.querySelectorAll('#table1 > tr');
  71. col.forEach((row) => row.children[index].style.backgroundColor = '');
  72. }
  73. td.innerText = j * i
  74. td.style.border = '1px solid #d3d3d3'
  75. td.style.padding = '10px'
  76. td.style.fontSize = '20px'
  77. td.style.textAlign = 'center'
  78. row.appendChild(td)
  79. }
  80. secondtable.appendChild(row)
  81. }
  82. document.body.appendChild(secondtable)
  83. // Calc
  84. // let calc = document.getElementById("calc");
  85. // let input1 = document.getElementById("input1");
  86. // let input2 = document.getElementById("input2");
  87. // calc.onclick = function () {
  88. // alert(`${(+input1.value) * (+input2.value)} km per week`);
  89. // }
  90. // Calc Live
  91. let calc = document.getElementById("calc");
  92. let input1 = document.getElementById("input1");
  93. let input2 = document.getElementById("input2");
  94. let result = document.getElementById("result");
  95. let calc1 = function () {
  96. return result.innerText = (+input1.value) * (+input2.value);
  97. }
  98. input1.oninput = calc1
  99. input2.oninput = calc1
  100. calc.onclick = calc1