-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreateTable.html
More file actions
61 lines (50 loc) · 1.79 KB
/
Copy pathcreateTable.html
File metadata and controls
61 lines (50 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<script async>
;(function() {
const tableList = document.querySelectorAll('.table-generate');
if (tableList == null) {
return;
}
for (let i = 0; i < tableList.length; i++) {
const ul = tableList[i];
const draw = {
th: '',
td: ''
};
const rows = ul.children;
for (let j = 0; j < rows.length; j++) {
const row = rows[j].children[0];
const columns = row.children;
const isHeader = /^th/.test(rows[j].innerHTML);
const colTag = isHeader ? 'th' : 'td';
let colData = '';
for (let k = 0; k < columns.length; k++) {
const column = columns[k];
const content = column.innerHTML;
colData += `<${colTag}>${content}</${colTag}>`;
}
const trHtml = `<tr>${colData}</tr>`
draw[colTag] += trHtml;
}
const result = `
<table>
<thead>${draw.th}</thead>
<tbody>${draw.td}</tbody>
</table>`
const targetId = ul.getAttribute('data-target-id');
document.getElementById(targetId).innerHTML = result;
ul.remove();
}
})();
;(function() {
const source = document.querySelectorAll('.dynamic-insert');
if (source == null) {
return;
}
for (let i = 0; i < source.length; i++) {
const item = source[i];
const target = item.getAttribute('data-target-selector');
document.querySelector(target).innerHTML = item.outerHTML;
item.remove();
}
})();
</script>