回答編集履歴
1
調整
test
CHANGED
@@ -12,3 +12,31 @@
|
|
12
12
|
console.log(tmp.firstChild.outerHTML);
|
13
13
|
});
|
14
14
|
```
|
15
|
+
|
16
|
+
# 調整
|
17
|
+
//sample.json
|
18
|
+
```json
|
19
|
+
{"button":["変更","削除"]}
|
20
|
+
```
|
21
|
+
```javascript
|
22
|
+
<script>
|
23
|
+
window.addEventListener('DOMContentLoaded',async()=>{
|
24
|
+
const data=await fetch('sample.json').then(res=>res.json()).then(x=>x.button);
|
25
|
+
const ul=document.querySelector('ul');
|
26
|
+
const li=document.createElement('li');
|
27
|
+
const buttons = document.createElement('span');
|
28
|
+
const attrs=[
|
29
|
+
{className:'btn btn-warning change',id:'changeID',onclick:()=>location.hash="modal-chg01"},
|
30
|
+
{className:'btn btn-info delete' ,id:'deleteID',onclick:()=>location.hash="modal-del01"},
|
31
|
+
];
|
32
|
+
data.forEach((x,y)=>{
|
33
|
+
const opt={...attrs[y],textContent:x};
|
34
|
+
const button = Object.assign(document.createElement('button'),opt);
|
35
|
+
buttons.appendChild(button);
|
36
|
+
});
|
37
|
+
li.appendChild(buttons);
|
38
|
+
ul.appendChild(li);
|
39
|
+
});
|
40
|
+
</script>
|
41
|
+
<ul></ul>
|
42
|
+
```
|