当我有一个bootstrap模式时,我想捕获导致它关闭的按钮类型。
<div id="fooModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel4" aria-hidden="true">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3 id="myModalLabel4">List</h3>
</div>
<div class="modal-body">
... whatever ...
</div>
<div class="modal-footer">
<button class='btn' data-dismiss='modal' aria-hidden='true'>Action 1</button>
<button class='btn btn-primary' aria-hidden='true'>Action 2</button>
<button class='btn' aria-hidden='true'>Action 3</button>
</div>
</div>
和脚本
$("#fooModal")
.modal({backdrop:'static'})
.on('hidden', function (event) {
console.log("foo hidden", event); // can't see the button, only the modal div itself
// candidates for what "closed" the modal:
// "x" button
// "Action 1"
// "Action 2"
// "Action 3"
})
.modal('show');
是否有对导致模态关闭的按钮的引用?
答案 0 :(得分:0)
如何处理按钮上的点击事件呢?
$('#fooModal [data-dismiss="modal"]').click(function(){
console.log($(this).text());
});