3

リモート ソースでブートストラップ 3 モーダル ダイアログを使用しています。私の問題は、これらのリモート ソースで外部の JavaScript とスクリプト ブロックを使用していることです。モーダル ダイアログを開いて閉じてから再度開くと、JavaScript が 2 回読み込まれます。

モーダル ダイアログを再度開いたときに、同じ JavaScript ファイルが再度読み込まれないようにするにはどうすればよいですか? または、ダイアログを閉じるときに、読み込まれた JavaScript を破棄するにはどうすればよいですか?

JavaScript :

$(function() {
    $('[data-load-remote]').on('click',function(e) {
        e.preventDefault();
        var $this = $(this);
        var remote = $this.data('load-remote');
        if(remote) {
            $($this.data('remote-target')).load(remote);
        }
    });
});

HTML :

<a href="#myModal" role="button" class="btn" data-toggle="modal" 
   data-load-remote="http://localhost/dashboard/myprices"
   data-remote-target="#myModal .modal-body">My Salon (Preview)</a>

<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog"
     aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal"
                aria-hidden="true">&times;</button>
        <h4 class="modal-title" id="myModalLabel">Modal title</h4>
      </div>
      <div class="modal-body">
      </div>
    </div><!-- /.modal-content -->
  </div><!-- /.modal-dialog -->
</div><!-- /.modal -->
4

1 に答える 1