我遇到了Bootstrap的modal和jQuery UI datepicker之间的冲突,我不能使用月份选择框,因为某些东西在打开后立即关闭了它。
复制步骤:
- 单击按钮“启动演示模式”
- 点击里面的输入框来激活日期选择器
- 点击选择框更改月份,你会看到它立即关闭
下面是一个示例:
$( function() {
$( "#datepicker" ).datepicker({
changeMonth: true
});
} );
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.11.0/jquery-ui.min.js"></script>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.css"/>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.11.0/jquery-ui.min.css"/>
<!-- Button trigger modal -->
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal">
Launch demo modal
</button>
<!-- Modal -->
<div class="modal fade" id="exampleModal" 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">
<input id="datepicker">
</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>
1条答案
按热度按时间oyt4ldly1#
在初始化jQuery时尝试使用
noConflict()
请参阅此链接jQuery noConflict()。另外,如果日期选择器被隐藏在模型后面,请使用
zindex
css属性并将其标记为重要。