|
@@ -6,26 +6,14 @@ table.style.cursor = 'pointer'
|
|
|
table.setAttribute('border', '1')
|
|
|
table.setAttribute('frame', 'void')
|
|
|
body.insertBefore(table, body.childNodes[0])
|
|
|
-let cells = []
|
|
|
-for (let rowIndex = 1; rowIndex < 10; rowIndex++) {
|
|
|
- let tr = document.createElement("tr")
|
|
|
- if (rowIndex % 2 === 0) {
|
|
|
- tr.style.backgroundColor = '#CFCFCF'
|
|
|
- }
|
|
|
- table.appendChild(tr)
|
|
|
- for (let colIndex = 1; colIndex < 10; colIndex++) {
|
|
|
- let td = document.createElement("td")
|
|
|
- cells.push(td)
|
|
|
- td.setAttribute('align', 'center')
|
|
|
- td.setAttribute('width', '40px')
|
|
|
- td.setAttribute('height', '40px')
|
|
|
- tr.appendChild(td)
|
|
|
- td.innerText = `${rowIndex*colIndex}`
|
|
|
|
|
|
- let currColor = []
|
|
|
- let currCells = []
|
|
|
+let cells = []
|
|
|
+let wrappFunc = (cells) => {
|
|
|
+ let currColor = []
|
|
|
+ let currCells = []
|
|
|
+ return (td, i, j) => {
|
|
|
td.onmouseover = function() {
|
|
|
- currCells = cells.filter(item => item.cellIndex === colIndex - 1 || item.parentElement.rowIndex === rowIndex - 1)
|
|
|
+ currCells = cells.filter(item => item.cellIndex === j - 1 || item.parentElement.rowIndex === i - 1)
|
|
|
for (const el of currCells) {
|
|
|
currColor.push(el.style.backgroundColor)
|
|
|
el.style.backgroundColor = 'red'
|
|
@@ -36,7 +24,29 @@ for (let rowIndex = 1; rowIndex < 10; rowIndex++) {
|
|
|
let color = currColor.shift()
|
|
|
el.style.backgroundColor = color
|
|
|
}
|
|
|
- }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+let innerFunc = wrappFunc(cells)
|
|
|
+
|
|
|
+for (let i = 1; i < 10; i++) {
|
|
|
+ let tr = document.createElement("tr")
|
|
|
+ if (i % 2 === 0) {
|
|
|
+ tr.style.backgroundColor = '#CFCFCF'
|
|
|
+ }
|
|
|
+ table.appendChild(tr)
|
|
|
+
|
|
|
+
|
|
|
+ for (let j = 1; j < 10; j++) {
|
|
|
+ let td = document.createElement("td")
|
|
|
+ cells.push(td)
|
|
|
+
|
|
|
+ td.setAttribute('align', 'center')
|
|
|
+ td.setAttribute('width', '40px')
|
|
|
+ td.setAttribute('height', '40px')
|
|
|
+ tr.appendChild(td)
|
|
|
+ td.innerText = `${i*j}`
|
|
|
+ innerFunc(td, i, j)
|
|
|
}
|
|
|
}
|
|
|
|