Bootstrap modal hide is not working

后端 未结 20 1320
温柔的废话
温柔的废话 2020-12-09 08:11

Bootstrap modal hide is not working. Alert comes in else. but my modal is not hidden Added bootply. My issue is the same one.

相关标签:
20条回答
  • 2020-12-09 08:52

    I had the same problem, tried a lot of things but the only solution that worked for me is @Tang Chanrith suggested to remove individually parts of the modal but a little bit improved to place back and the scrollbar. I'll put my answer just if the accepted answer did not work for them. Sorry for my english. Hope I helped.

    @Tang Chanrith

    Try this function

    function hideModal() {
      $("#myModal").removeClass("in");
      $(".modal-backdrop").remove();
      $("#myModal").hide();
    }
    

    Improved Sollution

    You just have to delete a class from body and css that generated

    function hideModal() {
      $("#myModal").removeClass("in");
      $(".modal-backdrop").remove();
      $('body').removeClass('modal-open');
      $('body').css('padding-right', '');
      $("#myModal").hide();
    }
    
    0 讨论(0)
  • 2020-12-09 08:53

    I have solution this problem.

    $('#landingpage, body').on('click',function(){
        $( ".action-close" ).trigger( "click" );});
    
    0 讨论(0)
  • 2020-12-09 08:53

    I am also having the same problem, where I can't find the correct solution for it.

    Later I observed that what is happening when the modal gets closed when it works well.

    Three Main properties are,

    • modal-open class gets removed from <body> tag.
    • In <body> tag change CSS .
    • <div> class of modal-backdrop gets removed.

    So, When u do these things manually, you will achieve it, when not works.

    The code should be as following in Jquery,

          $('body').removeClass('modal-open');        
          $('body').css('padding-right', '');
          $(".modal-backdrop").remove();
          $('#myModal').hide();
    

    Hence, try this and get a solution.

    0 讨论(0)
  • 2020-12-09 08:54

    You should try this $('.modal.in').modal('hide')

    Via https://github.com/twbs/bootstrap/issues/489

    0 讨论(0)
  • 2020-12-09 08:54

    Hide modal dialog box using bootstrap

    Method 1: using bootstrap

    $('.close').click(); 
    $("#MyModal .close").click();
    $('#myModalAlert').modal('hide');
    

    Method 2: using stop-propagation

    $("a.close").on("click", function(e){
      $("#modal").modal("hide");
      e.stopPropagation();
    });
    

    Method 3: After shown method invoke

    $('#myModal').on('shown', function () {
          $('#myModal').modal('hide');
    })
    

    Method 4: Using CSS

    this.display='block'; //Set block css
    this.display='none'; //set none css after close dialog
    
    0 讨论(0)
  • 2020-12-09 08:56

    I had same problem. Remove fade class.

    0 讨论(0)
提交回复
热议问题