Twitter bootstrap modal not working

后端 未结 5 1075
Happy的楠姐
Happy的楠姐 2021-02-05 02:54

I am new to Twitter Bootstrap. I am working on a modal panel, but it is not being displayed. It fades the screen, but the modal itself does not appear. I have checked the error

相关标签:
5条回答
  • 2021-02-05 03:05

    You need use the data-target tag.

    Try to replace the href="#myModal" attribute with data-target="#myModal". Besides, you have put a hide class, I guess it shouldn't be there.

    Look at the examples here

    0 讨论(0)
  • 2021-02-05 03:15

    I had the same issue, I realized i include the JQUERY library after BOOTSTRAP.

    Check to see that in your webpage you add/link first JQUERY and then Bootstrap

    0 讨论(0)
  • 2021-02-05 03:15

    Bootstrap Modal doesn't like Id's that start with a number.

    I had a UUID as my data-target and it did not work.

    <button data-target="#7CB2ED35-3AE1-44FD-AEA8-D953E5C953D5">Launch Modal</button>
    

    I solved it by pre-pend "M-" before all my UUID's so they're still unique:

    <button data-target="#M-7CB2ED35-3AE1-44FD-AEA8-D953E5C953D5">Launch Modal</button>
    

    0 讨论(0)
  • 2021-02-05 03:22

    Change this:

    <a data-toggle="modal" href="#myModal" class="btn btn-primary btn-large">Launch demo modal</a>
    

    To this:

    <button type="button" class="btn btn-primary btn-large" data-toggle="modal" data-target="#myModal">Launch demo modal</button>
    

    (remark that changing a tag to button tag is not the answer but it is adding the data-target and data-toggle attribute that does the "work")

    Please look at this example:

    <!DOCTYPE html >
    
    <html>
    <head>
        <title>Bootstrap Modal</title>
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>    
        <!-- Bootstrap -->
        <!-- Latest compiled and minified CSS -->
        <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.2/css/bootstrap.min.css">
        <!-- Optional theme -->
        <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.2/css/bootstrap-theme.min.css">
        <!-- Latest compiled and minified JavaScript -->
        <script src="//netdna.bootstrapcdn.com/bootstrap/3.0.2/js/bootstrap.min.js"></script>
    </head>
    <body>
        <button type="button" class="btn btn-primary btn-large" data-toggle="modal" data-target="#myModal">Launch demo modal</button>
    
        <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="purchaseLabel" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                        <h4 class="modal-title" id="purchaseLabel">Purchase</h4>
                    </div>
                    <div class="modal-body">
                        sup?
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                        <button type="button" class="btn btn-primary">Purchase</button>
                    </div>
                </div>
            </div>
        </div>
    </body>
    </html>
    
    0 讨论(0)
  • 2021-02-05 03:29

    In case someone run into this problem and none of the above works, I didn't have the css class fade in the class attribute of my modal

    I had the div of my modal like this

    <div class="modal" id="AdvanceSearchModal" tabindex="-1" role="dialog">
    

    I added fade class

    <div class="modal fade" id="AdvanceSearchModal" tabindex="-1" role="dialog">
    

    and with this the modal opens again

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