How can I unfocus the modal trigger button after closing the modal in bootstrap

前端 未结 3 436
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-02 04:36

I can\'t seem to blur the button after closing the modal.

$(\'#exampleModal\').on(\'hidden.bs.modal\', function(e){
        $(\'button\').blur();
    });
         


        
3条回答
  •  盖世英雄少女心
    2021-01-02 05:06

    My solution which works with multiple modals on page (based on Bootstrap modal examples):

    $('.modal').on('show.bs.modal', function (event) {
        var button = $(event.relatedTarget); // Button that triggered the modal
        button.one('focus', function (event) {
            $(this).blur();
        });
    });
    

提交回复
热议问题