回答編集履歴
2
調整
answer
CHANGED
@@ -40,4 +40,19 @@
|
|
40
40
|
<option value="黄" data-val="デザインB">黄</option>
|
41
41
|
</select>
|
42
42
|
</div>
|
43
|
+
```
|
44
|
+
|
45
|
+
# IE対応
|
46
|
+
```javascript
|
47
|
+
$(function(){
|
48
|
+
$('.child').each(function(){
|
49
|
+
$(this).clone().prop('disabled',true).removeClass('child').addClass('child2').hide().appendTo($(this).parent());
|
50
|
+
$(this).find('option:not(:first)').remove();
|
51
|
+
});
|
52
|
+
$('.parent').on('change',function(){
|
53
|
+
$(this).closest('.selectDiv').next('.selectDiv')
|
54
|
+
.find('.child option:not(:first)').remove().end()
|
55
|
+
.find('.child2 option[data-val="'+$(this).val()+'"]').clone().appendTo($(this).closest('.selectDiv').next('.selectDiv').find('.child'));
|
56
|
+
}).trigger('change');
|
57
|
+
});
|
43
58
|
```
|
1
調整
answer
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
```javascript
|
2
2
|
$(function(){
|
3
3
|
$('.selectDiv .parent').on('change',function(){
|
4
|
-
$(this).closest('.selectDiv').next('.selectDiv').find('.child option:not(:first)').hide().filter('[data-val="'+$(this).val()+'"]').show();
|
4
|
+
$(this).closest('.selectDiv').next('.selectDiv').find('.child option:not(:first)').hide().filter('[data-val="'+$(this).val()+'"]').show().end().end().find('.child option:first').prop('selected',true);
|
5
|
+
// 調整
|
6
|
+
// $(this).closest('.selectDiv').next('.selectDiv').find('.child option:not(:first)').hide().filter('[data-val="'+$(this).val()+'"]').show();
|
5
7
|
}).trigger('change');
|
6
8
|
});
|
7
9
|
```
|