Bootstrap 4:如何在第一次触发后删除模态的show.bs.modal事件

问题描述 投票:0回答:1

仅在打开共享模式时,我才使用此代码加载Twitter的Web意向javascript功能:

$(function(){
    $('#share').on('show.bs.modal', function(e){
        if(typeof(twttr) === 'undefined') {
            $.getScript('https://platform.twitter.com/widgets.js');
        }
    });
});

效果很好。现在,我也想在第一次触发时将show.bs.modal事件从模态中完全删除,因为事后完全没有必要。

我已经尝试过:

$('#share').off('show.bs.modal');

但是我猜测,由于这不是标准事件,因此不会那样工作。另外,我在引导文档中搜索了事件删除方法,但是里面似乎没有什么。

有什么想法吗?谢谢!

javascript jquery bootstrap-4 bootstrap-modal
1个回答
0
投票

您可以尝试.one()

$(function(){
  $('#share').one('show.bs.modal', function(e){
    if(typeof(twttr) === 'undefined') {
        $.getScript('https://platform.twitter.com/widgets.js');
    }
  });
});
© www.soinside.com 2019 - 2024. All rights reserved.