index.html 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. <main class="main">
  11. <div class="wrapper">
  12. <input type="number" id ='firstNum'> *
  13. <input type="number" id = 'secondNum'>
  14. <button id = 'calc'>Посчитать</button>
  15. Результат<input type="text" value=" " id = "result">
  16. </div>
  17. </main>
  18. <script>
  19. //Таблица умножения
  20. const table = document.createElement("table")
  21. for (let i = 1;i<= 9;i++){
  22. var row = document.createElement('tr');
  23. row.style.padding = '0px'
  24. for (let j = 1; j <= 9;j++){
  25. var cell = document.createElement('td')
  26. cell.appendChild(document.createTextNode(i*j))
  27. cell.style.border = '1px solid black'
  28. cell.style.padding = '10px'
  29. cell.style.margin = '0px'
  30. row.appendChild(cell);
  31. }
  32. table.appendChild(row);
  33. }
  34. document.body.appendChild(table)
  35. //Подсветить ячейку ++ Подсветить строку и столбец,
  36. const light = (event, color) => {
  37. const target = event.target;
  38. if (target.tagName === 'TD') {
  39. target.style.background = color;
  40. target.parentElement.style.background = color;
  41. const index = event.srcElement.cellIndex;
  42. const rows = document.querySelectorAll('tr');
  43. rows.forEach((row) => row.children[index].style.background = color);
  44. }
  45. }
  46. table.onmouseover = (event) => light(event, 'silver');
  47. table.onmouseout = (event) => light(event, '');
  48. //Calc
  49. const numberOne = document.getElementById('firstNum')
  50. const numberSecond = document.getElementById('secondNum')
  51. calc.onclick = (result) => document.getElementById('result')
  52. //Calc Live
  53. calc = () => result.value = ((+numberOne.value) * (+numberSecond.value))
  54. numberOne.oninput = calc
  55. numberSecond.oninput = calc
  56. </script>
  57. </body>
  58. </html>