回答編集履歴
3
ちょうせい
answer
CHANGED
@@ -39,4 +39,50 @@
|
|
39
39
|
<tbody>
|
40
40
|
</tbody>
|
41
41
|
</table>
|
42
|
+
```
|
43
|
+
# 上限あり
|
44
|
+
```javascript
|
45
|
+
<script>
|
46
|
+
window.addEventListener('DOMContentLoaded', ()=>{
|
47
|
+
const max=3;
|
48
|
+
const sub=document.querySelector('#sub');
|
49
|
+
document.querySelector('#btn').addEventListener('click',()=>{
|
50
|
+
if(sub.value=="notselect"){
|
51
|
+
alert('not selected!');
|
52
|
+
}else if([...document.querySelectorAll('#sublist tbody td')].map(x=>x.textContent).includes(sub.value)){
|
53
|
+
alert('already exists');
|
54
|
+
}else if([...document.querySelectorAll('#sublist tbody td')].length>=max){
|
55
|
+
alert(`can't regist anymore`);
|
56
|
+
}else{
|
57
|
+
document.querySelector('#sublist tbody').appendChild(
|
58
|
+
[Object.assign(document.createElement('td'),{textContent:sub.value})].reduce((x,y)=>{
|
59
|
+
x.appendChild(y);
|
60
|
+
return x;
|
61
|
+
},document.createElement('tr'))
|
62
|
+
);
|
63
|
+
}
|
64
|
+
});
|
65
|
+
});
|
66
|
+
</script>
|
67
|
+
|
68
|
+
<select id="sub">
|
69
|
+
<option value="notselect"></option>
|
70
|
+
<option value="01302年現代文Ba・月3水1">0130 2年現代文Ba・月3水1</option>
|
71
|
+
<option value="01312年現代文Bb・月4水2">0131 2年現代文Bb・月4水2</option>
|
72
|
+
<option value="01322年現代文Bc・月4金1">0132 2年現代文Bc・月4金1</option>
|
73
|
+
<option value="01332年現代文Bd・火2木2">0133 2年現代文Bd・火2木2</option>
|
74
|
+
<option value="01342年現代文Be・火4木2">0134 2年現代文Be・火4木2</option>
|
75
|
+
<option value="01352年現代文Bf・水1木4">0135 2年現代文Bf・水1木4</option>
|
76
|
+
<option value="01362年現代文Bg・水2金1">0136 2年現代文Bg・水2金1</option>
|
77
|
+
</select>
|
78
|
+
<button id="btn">追加</button>
|
79
|
+
<table border="1" id="sublist">
|
80
|
+
<thead>
|
81
|
+
<tr>
|
82
|
+
<th>科目リスト</th>
|
83
|
+
</tr>
|
84
|
+
</thead>
|
85
|
+
<tbody>
|
86
|
+
</tbody>
|
87
|
+
</table>
|
42
88
|
```
|
2
chousei
answer
CHANGED
@@ -39,70 +39,4 @@
|
|
39
39
|
<tbody>
|
40
40
|
</tbody>
|
41
41
|
</table>
|
42
|
-
```
|
43
|
-
# 調整版
|
44
|
-
```jaascript
|
45
|
-
<script>
|
46
|
-
window.addEventListener('DOMContentLoaded', ()=>{
|
47
|
-
const s1=document.querySelector('#s1');
|
48
|
-
const s2=s1.cloneNode(true);
|
49
|
-
const p=s1.parentNode;
|
50
|
-
s2.setAttribute('id','s2');
|
51
|
-
s2.querySelectorAll('.hide').forEach(x=>x.remove());
|
52
|
-
document.querySelector('#color').addEventListener('change',()=>{
|
53
|
-
if([...p.children].includes(s1)){
|
54
|
-
p.insertBefore(s2,s1);
|
55
|
-
s1.remove();
|
56
|
-
}else{
|
57
|
-
p.insertBefore(s1,s2);
|
58
|
-
s2.remove();
|
59
|
-
}
|
60
|
-
});
|
61
|
-
document.addEventListener('change',()=>{
|
62
|
-
const color=document.querySelector('#s1,#s2').value;
|
63
|
-
document.querySelectorAll('.s1_select').forEach(x=>{
|
64
|
-
x.style.display='none';
|
65
|
-
x.querySelector('select').disabled=true;
|
66
|
-
});
|
67
|
-
document.querySelector('#'+color).style.display='';
|
68
|
-
document.querySelector('#'+color+" select").disabled=false;
|
69
|
-
;
|
70
|
-
});
|
71
|
-
});
|
72
|
-
</script>
|
73
|
-
<label><input type="checkbox" id="color" name="color"> カラー</label>
|
74
|
-
<label>
|
75
|
-
<select id="s1">
|
76
|
-
<option value="white" class="hide">白</option>
|
77
|
-
<option value="red">赤</option>
|
78
|
-
<option value="black" class="hide">黒</option>
|
79
|
-
</select>
|
80
|
-
</label>
|
81
|
-
|
82
|
-
<div class="s1_select" id="white">
|
83
|
-
<label>
|
84
|
-
<select>
|
85
|
-
<option value="white1">WHITE1</option>
|
86
|
-
<option value="white2">WHITE2</option>
|
87
|
-
</select>
|
88
|
-
</label>
|
89
|
-
</div>
|
90
|
-
|
91
|
-
<div class="s1_select" id="red" style="display:none">
|
92
|
-
<label>
|
93
|
-
<select disabled>
|
94
|
-
<option value="red1">RED1</option>
|
95
|
-
<option value="red2">RED2</option>
|
96
|
-
</select>
|
97
|
-
</label>
|
98
|
-
</div>
|
99
|
-
|
100
|
-
<div class="s1_select" id="black" style="display:none">
|
101
|
-
<label>
|
102
|
-
<select disabled>
|
103
|
-
<option value="black1">BLACK1</option>
|
104
|
-
<option value="black2">BLACK2</option>
|
105
|
-
</select>
|
106
|
-
</label>
|
107
|
-
</div>
|
108
42
|
```
|
1
chousei
answer
CHANGED
@@ -39,4 +39,70 @@
|
|
39
39
|
<tbody>
|
40
40
|
</tbody>
|
41
41
|
</table>
|
42
|
+
```
|
43
|
+
# 調整版
|
44
|
+
```jaascript
|
45
|
+
<script>
|
46
|
+
window.addEventListener('DOMContentLoaded', ()=>{
|
47
|
+
const s1=document.querySelector('#s1');
|
48
|
+
const s2=s1.cloneNode(true);
|
49
|
+
const p=s1.parentNode;
|
50
|
+
s2.setAttribute('id','s2');
|
51
|
+
s2.querySelectorAll('.hide').forEach(x=>x.remove());
|
52
|
+
document.querySelector('#color').addEventListener('change',()=>{
|
53
|
+
if([...p.children].includes(s1)){
|
54
|
+
p.insertBefore(s2,s1);
|
55
|
+
s1.remove();
|
56
|
+
}else{
|
57
|
+
p.insertBefore(s1,s2);
|
58
|
+
s2.remove();
|
59
|
+
}
|
60
|
+
});
|
61
|
+
document.addEventListener('change',()=>{
|
62
|
+
const color=document.querySelector('#s1,#s2').value;
|
63
|
+
document.querySelectorAll('.s1_select').forEach(x=>{
|
64
|
+
x.style.display='none';
|
65
|
+
x.querySelector('select').disabled=true;
|
66
|
+
});
|
67
|
+
document.querySelector('#'+color).style.display='';
|
68
|
+
document.querySelector('#'+color+" select").disabled=false;
|
69
|
+
;
|
70
|
+
});
|
71
|
+
});
|
72
|
+
</script>
|
73
|
+
<label><input type="checkbox" id="color" name="color"> カラー</label>
|
74
|
+
<label>
|
75
|
+
<select id="s1">
|
76
|
+
<option value="white" class="hide">白</option>
|
77
|
+
<option value="red">赤</option>
|
78
|
+
<option value="black" class="hide">黒</option>
|
79
|
+
</select>
|
80
|
+
</label>
|
81
|
+
|
82
|
+
<div class="s1_select" id="white">
|
83
|
+
<label>
|
84
|
+
<select>
|
85
|
+
<option value="white1">WHITE1</option>
|
86
|
+
<option value="white2">WHITE2</option>
|
87
|
+
</select>
|
88
|
+
</label>
|
89
|
+
</div>
|
90
|
+
|
91
|
+
<div class="s1_select" id="red" style="display:none">
|
92
|
+
<label>
|
93
|
+
<select disabled>
|
94
|
+
<option value="red1">RED1</option>
|
95
|
+
<option value="red2">RED2</option>
|
96
|
+
</select>
|
97
|
+
</label>
|
98
|
+
</div>
|
99
|
+
|
100
|
+
<div class="s1_select" id="black" style="display:none">
|
101
|
+
<label>
|
102
|
+
<select disabled>
|
103
|
+
<option value="black1">BLACK1</option>
|
104
|
+
<option value="black2">BLACK2</option>
|
105
|
+
</select>
|
106
|
+
</label>
|
107
|
+
</div>
|
42
108
|
```
|