回答編集履歴
1
調整
test
CHANGED
@@ -55,4 +55,59 @@
|
|
55
55
|
<input type="button" id="dlg_open" value="open">
|
56
56
|
```
|
57
57
|
上記「次へ/前へ」についてはhtmlであらかじめスタティックに用意していますが、動的に設定することも可能です
|
58
|
-
|
58
|
+
# 参考
|
59
|
+
動的なnav
|
60
|
+
```html
|
61
|
+
<script>
|
62
|
+
window.addEventListener('DOMContentLoaded', ()=>{
|
63
|
+
let styleText="";
|
64
|
+
document.querySelectorAll('#dlg [name=select]').forEach((x,y,z)=>{
|
65
|
+
const n=dlg.querySelector('.close');
|
66
|
+
const span=Object.assign(document.createElement('span'),{className:`s s${y+1}`});
|
67
|
+
styleText+=`ul:has(#s${y+1}:checked) ~ #nav .s:not(.s${y+1}){display:none;} `;
|
68
|
+
if(y<=z.length-2){
|
69
|
+
const label=Object.assign(document.createElement('label'),{htmlFor:`s${y+2}`,textContent:'次へ'});
|
70
|
+
span.appendChild(label);
|
71
|
+
}
|
72
|
+
if(y>=1){
|
73
|
+
if(span.querySelector('label')){
|
74
|
+
span.appendChild(new Text(' | '));
|
75
|
+
}
|
76
|
+
const label=Object.assign(document.createElement('label'),{htmlFor:`s${y}`,textContent:'前へ'});
|
77
|
+
span.appendChild(label);
|
78
|
+
}
|
79
|
+
nav.appendChild(span);
|
80
|
+
});
|
81
|
+
document.head.appendChild(Object.assign(document.createElement('style'),{textContent:styleText}));
|
82
|
+
});
|
83
|
+
document.addEventListener('click',({target})=>{
|
84
|
+
if(target.matches('#dlg_open')){
|
85
|
+
dlg.showModal();
|
86
|
+
}
|
87
|
+
if(target.matches('#dlg .close')){
|
88
|
+
dlg.close();
|
89
|
+
}
|
90
|
+
});
|
91
|
+
</script>
|
92
|
+
<style>
|
93
|
+
#dlg li:not(:has([name="select"]:checked)){
|
94
|
+
display:none;
|
95
|
+
}
|
96
|
+
#dlg ul{
|
97
|
+
list-style:none;
|
98
|
+
padding:0;
|
99
|
+
}
|
100
|
+
[name=select]{display:none;}
|
101
|
+
</style>
|
102
|
+
<dialog id="dlg">
|
103
|
+
<ul>
|
104
|
+
<li><div><input type="radio" name="select" id="s1" checked>content 1</div></li>
|
105
|
+
<li><div><input type="radio" name="select" id="s2">content 2</div></li>
|
106
|
+
<li><div><input type="radio" name="select" id="s3">content 3</div></li>
|
107
|
+
<li><div><input type="radio" name="select" id="s4">content 4</div></li>
|
108
|
+
</ul>
|
109
|
+
<hr>
|
110
|
+
[ <span id="nav"></span> | <span class="close">閉じる</span> ]
|
111
|
+
</dialog>
|
112
|
+
<input type="button" id="dlg_open" value="open">
|
113
|
+
```
|