How to open a Bootstrap modal window using jQuery?

后端 未结 15 1841
闹比i
闹比i 2020-11-22 06:46

I\'m using Twitter Bootstrap modal window functionality. When someone clicks submit on my form, I want to show the modal window upon clicking the \"submit button\" in the fo

相关标签:
15条回答
  • 2020-11-22 07:44

    Bootstrap has a few functions that can be called manually on modals:

    $('#myModal').modal('toggle');
    $('#myModal').modal('show');
    $('#myModal').modal('hide');
    

    You can see more here: Bootstrap modal component

    Specifically the methods section.

    So you would need to change:

    $('#my-modal').modal({
        show: 'false'
    }); 
    

    to:

    $('#myModal').modal('show'); 
    

    If you're looking to make a custom popup of your own, here's a suggested video from another community member:

    https://www.youtube.com/watch?v=zK4nXa84Km4

    0 讨论(0)
  • 2020-11-22 07:45

    If you use links's onclick function to call a modal by jQuery, the "href" can't be null.

    For example:

    ... ...
    <a href="" onclick="openModal()">Open a Modal by jQuery</a>
    ... ...
    ... ...
    <script type="text/javascript">
    
    function openModal(){
    
        $('#myModal').modal();
    }       
    </script>
    

    The Modal can't show. The right code is :

    <a href="#" onclick="openModal()">Open a Modal by jQuery</a>
    
    0 讨论(0)
  • 2020-11-22 07:45

    Check out the complete solution here:

    http://www.w3schools.com/bootstrap/tryit.asp?filename=trybs_ref_js_modal_show&stacked=h

    Make sure to put libraries in required order to get result:

    1- First bootstrap.min.css 2- jquery.min.js 3- bootstrap.min.js

    (In other words jquery.min.js must be call before bootstrap.min.js)

        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
    
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js">
    </script> 
    
     <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    
    0 讨论(0)
提交回复
热议问题