load()多次触发

时间:2015-08-12 09:09:17

标签: javascript jquery

我已经使用off()作为模态,但是alert在第二次模态触发时多次触发,任何想法为什么会发生这种情况以及如何阻止它?

$('#my_modal').modal('show').off('shown.bs.modal').on('shown.bs.modal', function() {
    $('#head').load('example.com/email.html', function(){
        $.getScript('jquery.min.js', function(data){
            alert('debug');
        })
    });
});

1 个答案:

答案 0 :(得分:1)

一旦你绑定.on('shown.bs.modal',每次模态加载时都会被触发。

如果你想在第一次放映后解开它,试试这个:

$('#my_modal').modal('show').on('shown.bs.modal', function() {
  $('#my_modal').off('shown.bs.modal'); // might be able to use $(this).off('shown.bs.modal');
  $('#head').load('example.com/email.html', function(){
    $.getScript('jquery.min.js', function(data){
        alert('debug');
    })
  });
});