Browse Source

not full hw

Emmanuil 4 years ago
parent
commit
eac1a3a018
2 changed files with 63 additions and 0 deletions
  1. 22 0
      js-06/index.html
  2. 41 0
      js-06/js.js

+ 22 - 0
js-06/index.html

@@ -0,0 +1,22 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <meta name="viewport" content="width=device-width, initial-scale=1.0">
+    <title>Document</title>
+    <style>
+        table td {
+            border: 1px solid black;
+            padding: 20px;
+            width: 20px;
+            text-align: center;
+            font-size: 20px;
+            cursor: pointer;
+        }
+    </style>
+</head>
+<body>
+    
+    <script src="js.js"></script>
+</body>
+</html>

+ 41 - 0
js-06/js.js

@@ -0,0 +1,41 @@
+// var table = document.createElement("table");
+
+// for (i = 0; i < 10; i++) {
+//   var tr = document.createElement("tr");
+
+//   for (j = 0; j < 10; j++) {
+//     var td = document.createElement("td");
+//     var val = i * j;
+//     if (val === 0) {
+//       val = i || j;
+//     }
+
+//     // td.onmouseover = function(){
+//     //     this.setAttribute("style", "background-color:black; color: white;");
+//     // }
+//     // td.onmouseout = function(){
+//     //   this.setAttribute("style", "background-color:null;");
+//     // }
+
+//     td.innerHTML = val;
+//     tr.appendChild(td);
+//   }
+//   table.appendChild(tr);
+// }
+// document.body.appendChild(table);
+
+// var changeBg = (event, background, color) => {
+//   var target = event.target;
+//   if (target.tagName === "TD") {
+//     target.style.background = background;
+//     target.style.color = color;
+//     target.parentNode.style.background = background;
+//     target.parentNode.style.color = color;
+//     var index = event.srcElement.cellIndex;
+//     var tr = document.querySelectorAll("tr");
+//     tr.forEach((tr) => (tr.childNodes[index].style.background = background));
+//     tr.forEach((tr) => (tr.childNodes[index].style.color = color));
+//   }
+// };
+// table.onmouseover = (event) => changeBg(event, "black", "white");
+// table.onmouseout = (event) => changeBg(event, "", "");