bootstrap jquery show.bs.modal event won't fire

前端 未结 19 2278
小蘑菇
小蘑菇 2020-11-28 07:29

i\'m using the modal example from the bootstrap 3 docs. the modal works. however i need to access the show.bs.modal event when it fires. for now i\'m just trying:



        
相关标签:
19条回答
  • 2020-11-28 07:38

    Ensure that you are loading jQuery before you use Bootstrap. Sounds basic, but I was having issues catching these modal events and turns out the error was not with my code but that I was loading Bootstrap before jQuery.

    0 讨论(0)
  • 2020-11-28 07:38

    This happens when code might been executed before and it's not showing up so you can add timeout() for it tp fire.

    $(document).on('shown.bs.modal', function (event) {
          setTimeout(function(){
            alert("Hi");
          },1000); 
        });
    
    0 讨论(0)
  • 2020-11-28 07:39

    Below are the granular details:

    show.bs.modal works while model dialog loading shown.bs.modal worked to do any thing after loading. post rendering

    0 讨论(0)
  • 2020-11-28 07:40

    Make sure that you really use the bootstrap jquery modal and not another jquery modal.

    Wasted way too much time on this...

    0 讨论(0)
  • 2020-11-28 07:43

    Add this:

    $(document).ready(function(){
        $(document).on('shown.bs.modal','.modal', function () {
             // DO EVENTS
        });
    });
    
    0 讨论(0)
  • 2020-11-28 07:43

    Similar thing happened to me and I have solved using setTimeout.

    Bootstrap is using the following timeout to complete showing:

    c.TRANSITION_DURATION=300,c.BACKDROP_TRANSITION_DURATION=150,

    So using more than 300 must work and for me 200 is working:

    $('#myModal').on('show.bs.modal', function (e) {
        setTimeout(function(){
            //Do something if necessary
        }, 300);                        
    })
    
    0 讨论(0)
提交回复
热议问题