teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

1

結果を表に

2022/01/03 16:14

投稿

babu_babu_baboo
babu_babu_baboo

スコア616

answer CHANGED
@@ -8,9 +8,12 @@
8
8
  <style>
9
9
  fieldset, p {margin: 1ex; }
10
10
  body.edit section:not(.edit),
11
- body.question section:not(.question) {
11
+ body.question section:not(.question),
12
+ body.result section:not(.result)
13
+ {
12
14
  display: none;
13
15
  }
16
+ th { width: 5em; }
14
17
  </style>
15
18
 
16
19
  <body class="edit">
@@ -60,6 +63,13 @@
60
63
  <button id="BTN2">変数読み出し</button>
61
64
  </section>
62
65
 
66
+ <section class="result">
67
+ <h4>結果</h4>
68
+ <table border="1">
69
+ <thead><tr><th>a <th>b <th>c <th>d
70
+ <tbody id="TB"></tbody>
71
+ </table>
72
+ <section>
63
73
 
64
74
  <script>
65
75
  document.addEventListener ('change', ({target: e}, sec, out)=> {
@@ -110,9 +120,14 @@
110
120
  .filter (e=> e.querySelector('input[type="checkbox"]').checked)
111
121
  .map (e=> [...e.querySelectorAll ('output')].map (e=> parseInt (e.value, 10)));
112
122
 
123
+ document.body.className = 'result';
124
+ ary2tbody (rst2, TB);
113
125
  console.log(rst);
114
- console.log(rst2);
115
126
  }
127
+
128
+ function ary2tbody (ary, tb = document.createElement('tbody')) {
129
+ return ary.reduce((tb, a)=>(a.reduce((tr, str)=>(tr.insertCell().textContent = str, tr),tb.insertRow()), tb), tb);
130
+ }
116
131
  </script>
117
132
 
118
133