如何通过在模态窗口外部单击来关闭模态? [英] How to close a modal by clicking outside the modal window?

查看:69
本文介绍了如何通过在模态窗口外部单击来关闭模态?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在一个非常简单的jQuery模态中,我通过单击CLOSE as关闭该模态

In a very simple jQuery modal, I close the modal by clicking on CLOSE as

$('#close').click(function(e) {
  e.preventDefault();
  $('#overlay, #alertModalOuter').fadeOut(400, function() {
     $(this).remove();
  });
});

如何通过单击关闭"按钮(位于模态窗口内部)或单击模态窗口外部的任何位置来关闭模态.

How can I close the modal by clicking whether on CLOSE button (which is inside the modal windows) OR clicking anywhere outside the modal window.

推荐答案

像这样更改您的功能应该可以:

Changing your function like so should work:

    $('#close, #overlay').click(function(e) {
      e.preventDefault();
      $('#overlay, #alertModalOuter').fadeOut(400, function() {
      $('#close').remove();
    });
});

这篇关于如何通过在模态窗口外部单击来关闭模态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆