Bootstrap 模态框自定义点击和关闭事件【转载】

原文:https://blog.csdn.net/lm1022/article/details/79246673

模态框避免点击背景处关闭: 
1、div初始化时添加属性 aria-hidden=”true” data-backdrop=”static”

<div class="modal fade" id="edit" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden='true' data-backdrop='static'>

 

2、在需要显示模态框,初始化时

$(‘#myModal’).modal({
backdrop: ‘static’, 
//点击背景空白处不被关闭; 
keyboard: false
//触发键盘esc事件时不关闭。
}); 

 

自定义模态框显示和关闭触发事件:

   $(".classname").click(function () {
            $('#mymodel').modal('show');
              alert('模态框打开了');
        });

   $('#mymodel').on('hide.bs.modal', function () {
           alert('模态框关闭了');
   });

 

这里写图片描述

posted @ 2018-06-14 15:37  吃辣椒的小毛驴  阅读(7347)  评论(0编辑  收藏  举报