Browse Source

<HW7> 50%

Mark 2 years ago
parent
commit
cc79909e53
2 changed files with 79 additions and 0 deletions
  1. 16 0
      07/index1.html
  2. 63 0
      07/main.js

+ 16 - 0
07/index1.html

@@ -0,0 +1,16 @@
+<!DOCTYPE html>
+<html lang="en">
+
+<head>
+   <meta charset="UTF-8">
+   <meta http-equiv="X-UA-Compatible" content="IE=edge">
+   <meta name="viewport" content="width=device-width, initial-scale=1.0">
+   <title>Document</title>
+</head>
+
+<body>
+   <script src="main.js">
+   </script>
+</body>
+
+</html>

+ 63 - 0
07/main.js

@@ -0,0 +1,63 @@
+// // Таблица умножения + Подсветить ячейку
+// let table = document.createElement('table');
+// for (let i = 1; i < 10; i++) {
+//    let row = document.createElement('tr')
+//    for (let j = 1; j < 10; j++) {
+//       let td = document.createElement('td')
+//       td.onmouseover = function () {
+//          this.style.backgroundColor = 'red'
+//       }
+//       td.onmouseout = function () {
+//          this.style.backgroundColor = 'white'
+//          if (i % 2 !== 0) { this.style.backgroundColor = '#e9e9e9' }
+//          else { this.style.backgroundColor = 'white'; }
+//       }
+//       if (i % 2 !== 0) { td.style.backgroundColor = '#e9e9e9' }
+//       td.innerText = j * i
+//       td.style.border = '1px solid #d3d3d3'
+//       td.style.padding = '10px'
+//       td.style.fontSize = '20px'
+//       td.style.textAlign = 'center'
+//       row.appendChild(td)
+//    }
+//    table.appendChild(row)
+// }
+// document.body.appendChild(table)
+
+
+// Подсветить строку и столбец
+let table = document.createElement('table');
+for (let i = 1; i < 10; i++) {
+   let row = document.createElement('tr')
+   for (let j = 1; j < 10; j++) {
+      let td = document.createElement('td')
+      td.onmouseover = function () {
+         this.parentElement.style.backgroundColor = 'yellow'
+         let index = this.cellIndex;
+         let col = document.querySelectorAll('tr');
+         col.forEach((row) => row.children[index].style.backgroundColor = 'yellow');
+         this.style.backgroundColor = 'red';
+      }
+      td.onmouseout = function () {
+         this.style.backgroundColor = 'white'
+         this.parentElement.style.backgroundColor = ''
+         let index = this.cellIndex;
+         let col = document.querySelectorAll('tr');
+         col.forEach((row) => row.children[index].style.backgroundColor = '');
+      }
+      td.innerText = j * i
+      td.style.border = '1px solid #d3d3d3'
+      td.style.padding = '10px'
+      td.style.fontSize = '20px'
+      td.style.textAlign = 'center'
+      row.appendChild(td)
+   }
+   table.appendChild(row)
+}
+document.body.appendChild(table)
+
+// Calc
+
+
+
+