回答編集履歴
1
ちょうせい
answer
CHANGED
@@ -7,4 +7,34 @@
|
|
7
7
|
div_aaa.id = he[0];
|
8
8
|
div_bbb.id = he[1];
|
9
9
|
```
|
10
|
-
なのでは?
|
10
|
+
なのでは?
|
11
|
+
|
12
|
+
# sample
|
13
|
+
```javascript
|
14
|
+
<script>
|
15
|
+
const he = ["aaa","bbb"];
|
16
|
+
const id = ["ccc","ddd"];
|
17
|
+
const name_ccc=()=>{
|
18
|
+
const n =0;
|
19
|
+
const result = document.querySelector('#'+id[n]);
|
20
|
+
result.textContent += "ccc";
|
21
|
+
const input = Object.assign(document.createElement("input"),{
|
22
|
+
type:"button",
|
23
|
+
value:"次へ",
|
24
|
+
});
|
25
|
+
input.addEventListener('click',name_aaa);
|
26
|
+
result.appendChild(input);
|
27
|
+
}
|
28
|
+
const name_aaa=()=>{
|
29
|
+
const n =0;
|
30
|
+
document.querySelector('#'+he[n]).textContent += "aaa";
|
31
|
+
}
|
32
|
+
window.addEventListener('DOMContentLoaded', ()=>{
|
33
|
+
he.map(x=>Object.assign(document.createElement('div'),{id:x})).reduce((x,y)=>(x.appendChild(y),x),document.querySelector("#head"));
|
34
|
+
id.map(x=>Object.assign(document.createElement('div'),{id:x})).reduce((x,y)=>(x.appendChild(y),x),document.querySelector("#result"));
|
35
|
+
name_ccc();
|
36
|
+
});
|
37
|
+
</script>
|
38
|
+
<div id="head"></div>
|
39
|
+
<div id="result"></div>
|
40
|
+
```
|