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

前端 未结 19 2387
小蘑菇
小蘑菇 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:58

    Make sure you put your on('shown.bs.modal') before instantiating the modal to pop up

    $("#myModal").on("shown.bs.modal", function () { 
        alert('Hi');
    });
    $("#myModal").modal('show'); //This can also be $("#myModal").modal({ show: true });
    

    or

    $("#myModal").on("shown.bs.modal", function () { 
        alert('Hi');
    }).modal('show');
    

    To focus on a field, it is better to use the shown.bs.modal in stead of show.bs.modal but maybe for other reasons you want to hide something the the background or set something right before the modal starts showing, use the show.bs.modal function.

提交回复
热议问题