main.js 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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.createElement('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('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('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. // Calc
  55. // let calc = document.getElementById("calc");
  56. // let input1 = document.getElementById("input1");
  57. // let input2 = document.getElementById("input2");
  58. // calc.onclick = function () {
  59. // alert(`${(+input1.value) * (+input2.value)} km per week`);
  60. // }
  61. // Calc Live
  62. let calc = document.getElementById("calc");
  63. let input1 = document.getElementById("input1");
  64. let input2 = document.getElementById("input2");
  65. let result = document.getElementById("result");
  66. let calc1 = function () {
  67. return result.innerText = (+input1.value) * (+input2.value);
  68. }
  69. input1.oninput = calc1
  70. input2.oninput = calc1
  71. calc.onclick = calc1