Browse Source

<HW7>fix done

Mark 1 year ago
parent
commit
ff3cfda915
2 changed files with 35 additions and 3 deletions
  1. 2 0
      07/index1.html
  2. 33 3
      07/main.js

+ 2 - 0
07/index1.html

@@ -9,6 +9,8 @@
 </head>
 
 <body>
+   <table id="table"></table>
+   <table id="table1"></table>
    <input id="input1" type="number" placeholder="kmPerDay">
    <input id="input2" type="number" placeholder="walkPerDay">
    <button id="calc">enter</button><br>

+ 33 - 3
07/main.js

@@ -24,7 +24,7 @@
 
 
 // Подсветить строку и столбец
-let table = document.createElement('table');
+let table = document.getElementById('table');
 for (let i = 1; i < 10; i++) {
    let row = document.createElement('tr')
    for (let j = 1; j < 10; j++) {
@@ -32,7 +32,7 @@ for (let i = 1; i < 10; i++) {
       td.onmouseover = function () {
          this.parentElement.style.backgroundColor = 'yellow'
          let index = this.cellIndex;
-         let col = document.querySelectorAll('tr');
+         let col = document.querySelectorAll('#table > tr');
          col.forEach((row) => row.children[index].style.backgroundColor = 'yellow');
          this.style.backgroundColor = 'red';
       }
@@ -40,7 +40,7 @@ for (let i = 1; i < 10; i++) {
          this.style.backgroundColor = 'white'
          this.parentElement.style.backgroundColor = ''
          let index = this.cellIndex;
-         let col = document.querySelectorAll('tr');
+         let col = document.querySelectorAll('#table > tr');
          col.forEach((row) => row.children[index].style.backgroundColor = '');
       }
       td.innerText = j * i
@@ -54,6 +54,36 @@ for (let i = 1; i < 10; i++) {
 }
 document.body.appendChild(table)
 
+let secondtable = document.getElementById('table1');
+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('#table1 > 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('#table1 > 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)
+   }
+   secondtable.appendChild(row)
+}
+document.body.appendChild(secondtable)
+
 // Calc
 // let calc = document.getElementById("calc");
 // let input1 = document.getElementById("input1");