use*_*185 3 javascript jquery twitter-bootstrap bootstrap-modal
我正在尝试绑定一些代码以在我的模态打开时触发。我打开模态没有问题,但由于某种原因,我无法弄清楚我的事件没有触发。
这是我的模态
<div id="details" class="modal fade" style="display: none;" aria-hidden="true">
<div class="modal-dialog modal-">
<div class="modal-content">
<div class="modal-header">
<button class="close" type="button" data-dismiss="modal">×</button>
<h4 class="modal-title"></h4>
</div>
<div class="modal-body">
<p id="modal-body" class="text-defualt text- text-normal text-left"></p>
</div>
<div class="modal-footer"></div>
</div>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
这是我正在尝试运行的 JS 脚本
<script>
$(function(){ // let all dom elements are loaded
$("#details").on("show.bs.modal", function (e) {
alert("event fired");
});
})
</script>'
Run Code Online (Sandbox Code Playgroud)
我正在使用引导程序 3.3 和 jQuery v1.11.2
让我知道是否有更多信息有助于解决问题 提前致谢
请尝试以下代码:假设您在单击任何按钮时打开模态弹出窗口;添加下面的代码,它应该可以工作:参考这个 小提琴
<script>
$(function(){ // let all dom elements are loaded
$(document).on('show.bs.modal','#details', function () {
alert('hi');
});
});
</script>
Run Code Online (Sandbox Code Playgroud)