这是我的模态框 HTML 代码:
<div class="modal fade" id="delete-file-modal" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<form class="form-horizontal" method="post" id="delete_file_form">
<div class="modal-body">
Are you sure you want to delete this file?
</div>
<div class="modal-footer">
<button data-dismiss="modal" class="btn btn-danger" name="in_confirm_insert" id="confirm-delete-button">Delete</button>
<button data-dismiss="modal" class="btn btn-default" name="in_confirm_insert" id="cancel-delete-button">Cancel</button>
</div>
</form>
</div>
</div>
</div>
这是我的JavaScript代码:
$('#delete-file-modal').on('hidden.bs.modal', function (e) {
var delete_button = $(e.target).is("#confirm-delete-button");
if(delete_button === true) {
//delete file
alert("file deleted.");
} else {
alert("delete failed.");
};
});
我需要能够检查当删除文件模态框关闭时是否点击了删除按钮。我的 JavaScript 代码还缺少什么吗?
e.relatedTarget
显示 undefined。 - elquimista.hide()
也会被视为按下Escape键(因为document.activeElement被设置为body)。 - Jan Drábek