简体   繁体   English

单击其中的元素时,模态背景不会隐藏

[英]Modal backdrop doesn't hide when clicking an element inside it

On a page I have a modal with few <div class="message-container"> . 在页面上,我有一个<div class="message-container">很少的模态。 If the user clicks on that element, the page sends AJAX request for new modal. 如果用户单击该元素,则页面将发送AJAX请求以请求新的模式。 But when I close a new modal, I still have the backdrop from the first modal. 但是当我关闭一个新的模态时,我仍然具有第一个模态的背景。 All modals return PHP. 所有模态都返回PHP。 I have also tried closing the old modal before opening a new one but that still doesn't help. 我还尝试过在打开新模式之前关闭旧模式,但这仍然无济于事。

Here is the JS code: 这是JS代码:

$(document).on('click', '.message-container', function () {
    var messageId = $(this).attr('data-message-id');
    $.ajax({
        method: "POST",
        data: {
            action: 'readMessage',
            messageId: messageId
        }
    }).done(function (ret) {
        var obj = jQuery.parseJSON(ret);
        if (obj.code == 1) {
            $('#messages').modal('hide');
            $('.modal-container').html('');

            $('.modal-container').html(obj.value);
            $('#read-message').modal('toggle');
        } else {

        }
    });
});

$(document).on('click', '.unreadedMessages', function () {
    $.ajax({
        method: "POST",
        data: {
            action: 'getMessages'
        }
    }).done(function (ret) {
        var obj = jQuery.parseJSON(ret);
        if (obj.code == 1) {
            $('.modal-container').html(obj.value);
            $('#messages').modal('show');
        } else {
            var content = '<div class="alert alert-danger" id="messages-alert" role="alert">' + obj.value + '</div>';
        }
    })
});

unreadedMessages is first. 首先是unreadedMessages。

Not sure if this is exactly what you need, but here is a CSS pattern that I used when I have multiple modals open. 不知道这是否正是您所需要的,但这是我打开多个模式时使用的CSS模式。

body .modalBlockout ~ .modalBlockout {
    opacity: 0 !important;
}

This will hide any extra block out elements, and only shows the first one. 这将隐藏任何多余的阻止元素,并且仅显示第一个。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM