Bootstrap Modal immediately disappearing

后端 未结 27 1092
清歌不尽
清歌不尽 2020-12-04 07:18

I\'m working on a website using bootstrap.

Basically, I wanted to use a modal in the home page, summoned by the button in the Hero Unit.

Button code:

相关标签:
27条回答
  • 2020-12-04 07:32

    Have you tried removing

    data-dismiss="modal"
    
    0 讨论(0)
  • 2020-12-04 07:34

    In my case, I had the CDN included in the head of application.html.erb and also installed the 'jquery-rails' gem, which I am guessing thanks to the documentation and posts above, is redundant.

    I simply commented out the CDN (below) from the head of application.html.erb and the modal appropriately stays open.

    <!--<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>-->
    
    0 讨论(0)
  • 2020-12-04 07:35

    I too had the same issue, but for me it was happening because I had a button with type "submit" within the modal form. I changed

        <input  type='submit' name='submitname' id="partyBtn" value='Submit' title='Click to submit.'/>
    

    to

        <input  type='button' name='submitname' id="partyBtn" value='Submit' title='Click to submit.'/>
    

    And that fixed the disappearance issue.

    0 讨论(0)
  • 2020-12-04 07:36

    I had added bootstrap to my project via bower, then I imported the bootstrap.min.js file and after the modal.js file. (The button that opens the modal is inside a form). I just remove the import for modal.js and it works for me.

    0 讨论(0)
  • 2020-12-04 07:37

    Same symptom, in the context of a Rails application with Bootstrap provided by the bootstrap-sass gem, and @merv's answer put me on the right track.

    My application.js file had the following:

    //= require bootstrap
    //= require bootstrap-sprockets
    

    The fix was to remove one of the two lines. Indeed, the gem's readme warns you about this error. My bad.

    0 讨论(0)
  • 2020-12-04 07:37

    I had the same issue because I was toggling my modal twice as shown below:

    statusCode: {
        410: function (request, status, error) { //custom error code
    
            document.getElementById('modalbody').innerHTML = error;
            $('#myErrorModal').modal('toggle')
        }
    },
    error: function (request, error) {
    
        document.getElementById('modalbody').innerHTML = error;
        $('#myErrorModal').modal('toggle')
    }
    

    I removed one occurrence of:

    $('#myErrorModal').modal('toggle')

    and it worked like magic!

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