Bootstrap multiple modals modal-backdrop issue

前端 未结 5 1988
伪装坚强ぢ
伪装坚强ぢ 2021-01-02 07:09

I have a page where one Bootstrap modal opens another modal.

The problem is that with each opened modal, it adds

5条回答
  •  情歌与酒
    2021-01-02 07:41

    // Make sure only one backdrop is rendered 
     $(document).on('show.bs.modal', '.modal', function () {
            if ($(".modal-backdrop").length > 1) {
                $(".modal-backdrop").not(':first').remove();
            }
        });
        // Remove all backdrop on close
        $(document).on('hide.bs.modal', '.modal', function () {
            if ($(".modal-backdrop").length > 1) {
                $(".modal-backdrop").remove();
            }
        });

提交回复
热议问题