Bootstrap modal window inside another div

后端 未结 2 1678
萌比男神i
萌比男神i 2020-12-14 20:09

My bootstrap modal is working fine. My problem is that I need the modal window (including the gray background) to be applied on a div from the website and not on the body.

2条回答
  •  没有蜡笔的小新
    2020-12-14 20:35

    Here's an example I just did using your code and doing little tweaks to it.

    Click here and watch it working

    How to solve it:

    $(function () {
      
      //getting click event to show modal
        $('#submit-button').click(function () {
            $('#dialog_confirm_map').modal();
          
          //appending modal background inside the bigform-content
            $('.modal-backdrop').appendTo('.bigform-content');
          //removing body classes to enable click events
            $('body').removeClass();
        });
    
      
      //just to prove actions outside modal
        $('#help-button').click(function () {
            alert("Action with modal opened or closed");
        });
      //end just to prove actions outside modal
    });
    .bigform-content {
        border: solid 5px #DDD;
        margin: 30px 20px;
        overflow: hidden;
        padding:20px;
        position:relative;
    }
    .modal, .modal-backdrop {
        position: absolute !important;
    }
    .bigform-content h1 {
        margin:0;
    }
    .bigform-content input[type=submit] {
        margin-top:10px;
    }
    
    
    
    
    

    Hi, this is my form title

    This is my form

    Content outside div and modal

    Hope it

提交回复
热议问题