모달 내에서 select2를 다루고 있습니다. 나는 수 주 전에 그것을 연구 중이다. 나는 몇몇 게시물을 읽었으나 아무런 해결책도 없다. 예를 들어 :select2가 모달로 작동하지 않습니다.
Select2 doesn't work when embedded in a bootstrap modal
Select2 not working inside bootstrap modal
코드는 다음과 같습니다
<div id="modal_sg" class="modal fade" style="overflow: hidden;">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title">Please select a corporation</h4>
</div>
<div class="modal-body">
<form id="form_ag" class="form form-horizontal">
<input type="hidden" style="display:none;" value="32" name="id">
<div class="form-group">
<label for="id_sg" class="control-label col-md-3">Corporation</label>
<div class="col-md-9">
<select class="form-control select2" id="id_sg" name="id_sg">
<option value="89">a</option>
<option value="115">b</option>
<option value="84">c</option>
</select>
</div>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
<button type="button" class="btn btn-primary" id="bt_modal_sg">Save</button>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
자바 스크립트 :
$('.select2').select2(
{dropdownParent: $('#modal_sg')}
);
CSS는 : 나는 select2-4.0.3을 사용하고
.select2-container {
width: 100% !important;
padding: 0;
}
. 나는이 문제를 고칠뿐만 아니라 내 코드에서 무엇이 잘못되었는지 모른다. 어떤 도움이라도 대단히 감사하겠습니다. 미리 감사드립니다!
정확히 무엇이 문제입니까? "일하지 않는다"는 것은 꽤 불분명하다. – Shrike
select2는 모달을 제외하고는 정상적으로 작동합니다. 드롭 다운을 클릭하면 펼치기/접기 기호가 변경되지만 드롭 다운 목록이 표시되지 않습니다. 내가 찾은 모든 솔루션을 테스트했지만 그 중 아무 것도 나를 위해 작동하지 않습니다. 내 코드에 잘못된 것이 있지만 확신 할 수 없다. – plectranthus