我的页面上有一个按钮。目前,它正在打开一个引导程序模式,我现在还不想这样做。
我的html包括:
<div class='bookmarkButtonDiv'>
<button type='button' class="btn btn-primary" data-toggle='modal' data-target='#newModal' id="IBtn">Bookmark</button>
</div>
我的模态代码包括
<div class="modal fade" id="newModal" role="dialog">
<!-- some code to populate the modal -->
在我的Javascript中
jQuery.noConflict();
(function($) {
$(function () {
$('#IBtn').click(function (e) {
console.log('button clicked'
});
});
})(jQuery);
由于某种原因,这将打开引导程序模式,并写入控制台。我要做的就是将其写入控制台。最终,该按钮将被链接以打开模式,但是现在我只想在控制台中进行测试。
我正在使用Bootstrap 4.3
最佳答案
删除data-toggle='modal' data-target='#newModal'
。当您单击具有那些属性的元素时,Bootstrap会自动附加事件处理程序以打开模式。
jQuery.noConflict();
(function($) {
$(function () {
$('#IBtn').click(function (e) {
console.log('button clicked');
});
});
})(jQuery);
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet"/>
<div class='bookmarkButtonDiv'>
<button type='button' class="btn btn-primary" id="IBtn">Bookmark</button>
</div>
<div class="modal fade" id="newModal" role="dialog">
<h1>Modal contents</h1>
</div>
关于javascript - 自举模态开放,当它不应该,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/57279165/