2016-08-03 11 views
0

ビデオを含むiframeをモーダルに開くための簡単なハンドラを作成しました。 2つのページから2つのビデオがあります。私は任意のファイルがファイル名に基づいて読み込むことができるように関数を再利用したいです。私はそれが単純な構文であることを知っています、それが何であるか分かりません。ファイル名に基づくJQueryロードファイル

リンク:

<a href="#" data-toggle="modal" data-target="#videoPopup" class="modal-link">` 

機能:

$('.desktop-cta-mod .modal-link').on('click', function() { 
    $('#videoPopup .modal-content').load('Content/video.html', function() { 
     //bind closers 
     $('.modal-backdrop, .modal-content button').off().on('click', function() { 
      $('#videoPopup .modal-content').empty(); 
      $('.modal-backdrop').remove(); 
     }); 
    }) 
}); 

答えて

1

データがあなたのリンクタグに属性とクリックしたときに、現在のクリックされた項目から読んであなたは2つの異なるページ/ URLを保つことができます。

<a href="#" data-toggle="modal" data-target="#videoPopup" 
            data-videourl="Content/video.html" class="modal-link"> 
<a href="#" data-toggle="modal" data-target="#videoPopup" 
            data-videourl="Content/video2.html" class="modal-link"> 

とあなたのJavascriptを

$('.desktop-cta-mod .modal-link').on('click', function() { 
    var url=$(this).data("videourl"); 
    $('#videoPopup .modal-content').load(url, function() { 
     //bind closers 
     $('.modal-backdrop, .modal-content button').off().on('click', function() { 
      $('#videoPopup .modal-content').empty(); 
      $('.modal-backdrop').remove(); 
     }); 
    }) 
}); 

はちょうどあなたが正しくURL値をレンダリングしていることを確認してくださいになります。コンテンツディレクトリがルートレベルにある場合は、/Content/Video.html

+1

これは完璧です!そのように考えたことはありません。優れた答え。 – thinkbliss

関連する問題