Twitter Bootstrap cant stop a dropdown from closing on click

前端 未结 2 1141
南方客
南方客 2020-12-10 07:34

I have looked at the other questions similar and tried many of the solutions, but none have worked. Here is the issue, this is a mini login form for the top banner. I need

相关标签:
2条回答
  • 2020-12-10 07:54

    I was having the same problem with an accordion/toggle sub-menu that was nested within a dropdown-menu in Bootstrap 3. Borrowed this syntax from the source code to stop all collapse toggles from closing the dropdown:

    $(document).on(
        'click.bs.dropdown.data-api', 
        '[data-toggle="collapse"]', 
        function (e) { e.stopPropagation() }
    );
    

    You can replace [data-toggle="collapse"] with whatever you want to stop closing the form, e.g. another class or another data property.

    0 讨论(0)
  • 2020-12-10 08:15

    I figured it out. It was not inside the document ready function. (hat tip to Koala_dev) Javascript needs to be:

        <script type="text/javascript">
    
        $(document).ready(function() {
            $(document).on('click', '.dropdown-menu', function (e) {
                $(this).hasClass('keep_open') && e.stopPropagation(); // This replace if conditional.
            }); 
        });
        </script>
    
    0 讨论(0)
提交回复
热议问题