How to make modal close on click outside

后端 未结 7 706
误落风尘
误落风尘 2020-12-19 02:05

I have used this JavaScript below:

7条回答
  •  庸人自扰
    2020-12-19 02:41

    This seemed to be the code that worked out for me in the end:

    $(document).click(function (e) {
        if ($(e.target).is('#openModal')) {
            $('#openModal').fadeOut(500);
        }
    
    });
    
    $("#modalNo").click(function () {
        $("#openModal").fadeOut(500);
    
    
    });
    $(".close").click(function () {
        $("#openModal").fadeOut(500);
    });
    $(".close-circle").click(function () {
        $("#openModal").fadeOut(500);
    });
    

提交回复
热议问题