我试图在bootstrap模式中使用bootstrap multi-select。我能够初始化它并完美呈现它没有问题。我面临一个非常烦人的问题,当我尝试拖动模态内的滚动条时,下拉关闭。我尝试并在bootstrap模式之外复制相同的代码,它完美地工作。我已经创建了jsFiddle来演示这个问题。
正常滚动工作正常但拖动模式中的滚动条会关闭下拉列表。有什么方法可以解决这个问题吗?
<!-- Button trigger modal -->
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#myModal">
Launch demo modal
</button>
<select id="example-multiple-selected1" multiple="multiple">
<option value="1">Option 1</option>
<option value="2" selected="selected">Option 2</option>
<!-- Option 3 will be selected in advance ... -->
<option value="3" selected="selected">Option 3</option>
<option value="4">Option 4</option>
<option value="5">Option 5</option>
<option value="6">Option 6</option>
</select>
<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Modal title</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<select id="example-multiple-selected" multiple="multiple">
<option value="1">Option 1</option>
<option value="2" selected="selected">Option 2</option>
<!-- Option 3 will be selected in advance ... -->
<option value="3" selected="selected">Option 3</option>
<option value="4">Option 4</option>
<option value="5">Option 5</option>
<option value="6">Option 6</option>
</select>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div>
<script>
$('#example-multiple-selected').multiselect({
maxHeight: 100
});
$('#example-multiple-selected1').multiselect({
maxHeight: 100
});
</script>
答案 0 :(得分:1)
以下是您的解决方案:
$('.modal').on('mousedown mouseup click', '.multiselect-container', function(e) {
e.preventDefault();
});