Vika 2 years ago
parent
commit
4dcf6be303
3 changed files with 186 additions and 0 deletions
  1. 13 0
      js6/index.html
  2. 169 0
      js6/main.js
  3. 4 0
      js6/style.css

+ 13 - 0
js6/index.html

@@ -0,0 +1,13 @@
+<!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>
+  <link href="style.css" rel="stylesheet"> 
+</head>
+<body>
+  <script src="main.js"></script>
+</body>
+</html>

+ 169 - 0
js6/main.js

@@ -0,0 +1,169 @@
+// Task Таблица умножения
+let myTable = document.createElement('table');
+
+let body=  document.getElementsByTagName('body')[0];
+
+
+body.append(myTable)
+
+for (let i = 0; i < 10; i++){
+  let myTr = document.createElement('tr');
+  let myTd = document.createElement('td');
+  
+   myTable.appendChild(myTr).appendChild(myTd).innerText = `${i}`;
+
+    for (let q = 1; q < 10; q ++) {
+      let myTd1= document.createElement('td');
+      
+      if (i === 0) {
+        myTr.appendChild(myTd1).innerText = `${q}`;
+      };
+
+      if (i > 0) {
+        let resultMultiplication = i * q;
+        myTr.appendChild(myTd1).innerText = `${resultMultiplication}`;   
+      };
+  };
+};
+
+// Task Подсветить ячейку
+
+//let td = document.querySelectorAll('td');
+// for (let w = 0; w < td.length; w++) {
+//   td[w].onmouseover = function () {
+
+//     this.style.backgroundColor = 'red';
+//   };
+//   td[w].onmouseout = function () {
+//     this.style.backgroundColor = '';
+//   };
+// };
+
+//Task Подсветить строку и столбец,
+
+// let td = document.querySelectorAll('td');
+// for (let a = 0; a < td.length; a++) {
+//   let trList = document.querySelector('table').getElementsByTagName('tr');
+  
+//   td[a].onmouseover = function () {
+//     td[a].parentElement.style.backgroundColor = 'red';
+//     let p = this.cellIndex; 
+    
+//     for (let q = 0; q < trList.length; q++) {
+//       trList[q].getElementsByTagName('td')[p].style.backgroundColor = 'red';
+//     }
+//   };  
+
+//   td[a].onmouseout = function () {
+//     td[a].parentElement.style.backgroundColor = '';
+
+//     for (let r = 0; r < trList.length; r++) {
+//       let p = this.cellIndex; 
+//       trList[r].getElementsByTagName('td')[p].style.backgroundColor = '';
+//     }
+//   }
+// }
+
+
+// //Task 
+// let input1 = document.createElement('input');
+// input1.id = 'input1';
+// input1.type = 'number';
+// input1.style.display ='block';
+// input1.style.marginTop = '20px';
+
+// let input2 = document.createElement('input');
+// input2.id = 'input2';
+// input2.type = 'number';
+// input2.style.display ='block';
+
+// let inputResult = document.createElement('input');
+// inputResult.id = 'result';
+// inputResult.type = 'text';
+// inputResult.style.display ='block';
+
+// let inputSum = document.createElement('button');
+// inputSum.id = 'sum';
+// inputSum.innerText = 'Sum';
+
+// let inputMinus = document.createElement('button');
+// inputMinus.id = 'minus';
+// inputMinus.innerText = 'Minus';
+
+// body.appendChild(input1);
+// body.appendChild(input2);
+// body.appendChild(inputResult);
+// body.appendChild(inputMinus);
+// body.appendChild(inputSum);
+
+// function getSum () {
+//   let result = +(input1.value) + (+input2.value);
+//   inputResult.value = `${result}`;
+//   return;
+  
+// };
+
+// function getDifference() {
+//   let result = input1.value - input2.value;
+//   inputResult.value = `${result}`;
+//   return;
+// };
+
+// inputSum.addEventListener('click', getSum);
+// inputMinus.addEventListener('click', getDifference);
+
+// //Task 
+// let input1 = document.createElement('input');
+// input1.id = 'input1';
+// input1.type = 'number';
+// input1.style.display ='block';
+// input1.style.marginTop = '20px';
+
+// let input2 = document.createElement('input');
+// input2.id = 'input2';
+// input2.type = 'number';
+// input2.style.display ='block';
+
+// let inputResult = document.createElement('input');
+// inputResult.id = 'result';
+// inputResult.type = 'text';
+// inputResult.style.display ='block';
+// inputResult.placeholder = "result";
+
+// body.appendChild(input1);
+// body.appendChild(input2);
+// body.appendChild(inputResult);
+
+
+// function calc() {
+//   inputResult.value = (+input1.value) + (+input2.value);
+// }
+
+// input1.oninput = calc;
+// input2.oninput = calc;
+
+  
+//Task доп задание на паре
+let td = document.querySelectorAll('td');
+for (let a = 0; a < td.length; a++) {
+  let trList = document.querySelector('table').getElementsByTagName('tr');
+  
+  td[a].onmouseover = function () {
+    td[a].parentElement.style.backgroundColor = 'red';
+    let p = td[a].cellIndex; 
+    
+    for (let q = 0; q < trList.length; q++) {
+      trList[q].getElementsByTagName('td')[p].style.backgroundColor = 'red';
+    }
+  };  
+
+  td[a].onmouseout = function () {
+    td[a].parentElement.style.backgroundColor = '';
+
+    for (let r = 0; r < trList.length; r++) {
+      let p = td[a].cellIndex; 
+      trList[r].getElementsByTagName('td')[p].style.backgroundColor = '';
+    }
+  }
+}
+

+ 4 - 0
js6/style.css

@@ -0,0 +1,4 @@
+td {
+  border:solid black;
+  width: 20px;
+}