How to close a modal by clicking outside the modal window?
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.
像这样改变你的功能应该工作:
$('#close, #overlay').click(function(e) {
e.preventDefault();
$('#overlay, #alertModalOuter').fadeOut(400, function() {
$('#close').remove();
});
});
我发现包含以下内容很有帮助:
$('.item-modal').click(function(e) {
e.stopPropagation();
});
将相同的点击侦听器添加到叠加层。
链接地址: http://www.djcxy.com/p/83984.html上一篇: 关闭Bootstrap模态
下一篇: 如何通过点击模式窗口外部来关闭模式?