gpt4 book ai didi

jquery - Bootstrap Multiselect 滚动条拖动在 Bootstrap Modal 中不起作用

转载 作者:太空宇宙 更新时间:2023-11-04 07:56:56 25 4
gpt4 key购买 nike

我正在尝试在 Bootstrap 模式中使用 Bootstrap 多选。我能够初始化它并完美地渲染它,没有任何问题。我面临一个非常烦人的问题,当我尝试将滚动条拖动到模态框内时,下拉菜单会关闭。我尝试并在 Bootstrap 模式之外复制了相同的代码,它工作得很好。我创建了 jsFiddle 来演示这个问题。

正常滚动效果很好,但在模式中拖动滚动条会关闭下拉菜单。有什么办法可以解决这个问题?

JSFiddle Link

<!-- 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">&times;</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>

最佳答案

这是您的解决方案:

$('.modal').on('mousedown mouseup click', '.multiselect-container', function(e) {
e.preventDefault();
});

工作 Jsfiddle:https://jsfiddle.net/scooterlord/hdnf9x61/10/

关于jquery - Bootstrap Multiselect 滚动条拖动在 Bootstrap Modal 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47258715/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com