表の結合、舐めてました。難しい。4時間もかかってしまいました。笑。皆さんのコードのほうが素晴らしかった。。。
view
1table
2 thead
3 tr
4 td 18年度
5 td 18年度
6 td 19年度
7 td 19年度
8 td 19年度
9 td 19年度
10 td 19年度
11 td 19年度
12 tbody
13 tr.quarter
14 td 18下期
15 td 18下期
16 td 19上期
17 td 19上期
18 td 19上期
19 td 19上期
20 td 19上期
21 td 19上期
22 tr
23 td 18/11
24 td 18/12
25 td 19/01
26 td 19/02
27 td 19/03
28 td 19/04
29 td 19/05
30 td 19/06
javascript
1 let thead_td = document.querySelectorAll("thead td"),
2 tbody_td = document.querySelectorAll("tbody tr.quarter td"),
3 t_text = {},
4 counts = {};
5 textCount(thead_td);
6 let thead = document.querySelector("thead");
7 textSpan(thead, counts);
8
9 textCount(tbody_td);
10 let tbody = document.querySelector("tbody tr.quarter");
11 textSpan(tbody, counts);
12
13 function textSpan(par,text){
14 let td = [];
15 while (par.firstChild) {
16 par.removeChild(par.firstChild);
17 };
18 for (let i = 0; i < Object.keys(text).length; i++) {
19 td[i] = document.createElement("td");
20 td[i].setAttribute('colSpan', Object.values(text)[i]);
21 td[i].textContent= Object.keys(text)[i];
22 par.appendChild(td[i]);
23 };
24 };
25 function textCount( text ){
26 t_text = {};
27 counts = {};
28 for (let i = 0; i < text.length; i++) {
29 t_text[i] = text[i].textContent;
30 let key = t_text[i]
31 counts[key] = (counts[key])? counts[key] + 1 : 1 ;
32 };
33 };