index.html 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>Document</title>
  7. <style>
  8. td {
  9. border: 1px solid grey;
  10. width: 20px;
  11. height: 20px;
  12. text-align: center;
  13. }
  14. /* td:hover{
  15. background-color: hotpink;
  16. } */
  17. </style>
  18. </head>
  19. <body>
  20. <h2>Таблица умножения</h2>
  21. <input type="text" id='inputrows' placeholder="Введите количество строк">
  22. <input type="text" id='inputcolumns' placeholder="Введите количество столбцов">
  23. <button id="button">Расчитать</button>
  24. <div id='div'></div>
  25. <h2>Calc</h2>
  26. <input type="text" id="power" placeholder="Enter power of 1 lamp--W">
  27. <input type="text" id="numeric" placeholder="Enter number of lamps--part/parts">
  28. <input type="text" id="hours" placeholder="Enter the working lamp`s hours--hour/hours">
  29. <button id="calc">Calculate</button>
  30. <div id="data"></div>
  31. <script>
  32. // Таблица умножения && Подсветить ячейку && Подсветить строку и столбец,
  33. var rows = document.getElementById('inputrows')
  34. var colums = document.getElementById('inputcolumns')
  35. var button = document.getElementById('button')
  36. var div = document.getElementById('div')
  37. button.onclick = function () {
  38. rows.value = +rows.value
  39. colums.value = +colums.value
  40. var table = document.createElement('table');
  41. div.appendChild(table);
  42. for (let i = 1; i <= rows.value; i++) {
  43. var tr = document.createElement('tr');
  44. table.appendChild(tr);
  45. for (let j = 1; j <= colums.value; j++) {
  46. var td = document.createElement('td');
  47. tr.appendChild(td);
  48. var val = i * j;
  49. td.innerText = val
  50. //Подсветить ячейку
  51. // td.onmouseover = function (event) {
  52. // this.style.backgroundColor = 'red'
  53. // }
  54. // td.onmouseout = function (event) {
  55. // this.style.backgroundColor = 'yellow'
  56. // }
  57. //Подсветить строку и столбец,
  58. td.onmouseover = function (event) {
  59. //console.log(this, event) //event - это объект с информацией о событии,
  60. //передается первым параметром в обработчик события;в обработчик события в качестве
  61. //this передается элемент, на котором событие произошло;
  62. this.parentElement.style.backgroundColor = 'pink'
  63. var x = this.cellIndex
  64. var rows = document.querySelectorAll('tr')
  65. rows.forEach((item) => item.children[x].style.backgroundColor = 'pink')
  66. this.style.backgroundColor = 'red'
  67. }
  68. td.onmouseout = function (event) {
  69. this.parentElement.style.backgroundColor = ''
  70. var x = this.cellIndex
  71. var rows = document.querySelectorAll('tr')
  72. rows.forEach((item) => item.children[x].style.backgroundColor = '')
  73. this.style.backgroundColor = ''
  74. }
  75. }
  76. }
  77. }
  78. //Calc && Calc Live
  79. var Power = document.getElementById('power')
  80. var Numeric = document.getElementById('numeric')
  81. var Hours = document.getElementById('hours')
  82. var Calc = document.getElementById('calc')
  83. var Data = document.getElementById('data')
  84. // do{
  85. // alert('Fill the fields of input')
  86. //}
  87. //while (Power.value !=='' && Numeric.value !=='' && Hours.value !=='') {
  88. //if(Power.value ==true && Numeric.value == true && Hours.value == true){
  89. // //if(true){
  90. function calc() {
  91. var Result = ((+Power.value) * (+Numeric.value) * (+Hours.value)) / 1000
  92. Data.innerHTML += `<p style="background-color: rgb(146, 228, 231); border-radius: 10px; padding: 15px">
  93. Power of lamp/lamps: ${Power.value}; </br> Number of lamp/lamps: ${Numeric.value}; </br>
  94. Working hours of lamp/lamps: ${Hours.value}; </br> Result calculates in kilo-Watts: ${Result}</p>`
  95. //alert('Result calculates in kilo-Watts: ' + Result)
  96. }
  97. Power.oninput = calc
  98. Numeric.oninput = calc
  99. Hours.oninput = calc
  100. // }else{
  101. // alert('Fill the fields of input')
  102. // }
  103. </script>
  104. </body>
  105. </html>