2013-06-28 19 views
2

所以我今天的問題是關於更新jQuery modal,以便可以從加載的子模板中的按鈕調用它。

如何更新這個jQuery模式,以在加載的模板頁面上定位選擇器

對我而言,我使用的是2kb PopEasy modal。在我的金字塔項目中,我將模態坐在主模板的頂部。打開模式的按鈕位於加載到主模板中的子頁面模板上。

enter image description here

<body id="body-dashboard"> 
    <div id="modalrequest" class="modal"> 
     <section id="intro-request"> 
      <h1>The Modal</h1> 

加載的模板頁面上生成的標記:

<td class="table-request-btn incoming-icon"> 
    <a href="#modalrequest" class="modalLink">Request Intro</a> 
    <button class="modalLink" href="#modalrequest">Request Intro</button> 
</td> 



現在目前的方式模態jQuery是設置,我不能得到它工作。 #body-dashboard是主模板中主容器的標識。 .modalLink是加載模板中的按鈕上的類。

// PopEasy for Request Intro 
    var modalObj = $('#body-dashboard'); 
    //var modalObj = $('.modalLink'); 
    if (modalObj.length && modalObj.modal) { 

     modalObj.modal({ 
      trigger: '.modalLink', 
      olay:'div.overlay', 
      modals:'div.modal', 
      animationEffect: 'fadeIn', 
      animationSpeed: 400, 
      moveModalSpeed: 'slow', 
      background: '000', 
      opacity: 0.8, 
      openOnLoad: false, 
      docClose: true, 
      closeByEscape: true, 
      moveOnScroll: true, 
      resizeWindow: true, 
      close:'.closeBtn' 
     }); 
    } 



現在,當我第一次遇到這個問題,我remembered an older issue I had與努力的目標動態創建的類。

這是解決方案:

$("body").on("click", ".register_unselected", function(){}); 



我能夠使用該技術來讓我裝模板按鈕後觸發警報:

$("#body-dashboard").on("click", ".modalLink", function(){ 
    alert('this works!'); 
}); 



不過我仍然沒有嘗試在模式上使用相同的東西

var modalObj = $('#body-dashboard .modalLink'); 
modalObj.modal({ 
    trigger: '#body-dashboard .modalLink', 



你會如何解決這個問題?你需要看更多的代碼嗎?

回答

2

加載新模板後,必須調用模態初始化函數。

+0

啊謝謝!/faceplam ...另外7分鐘:) –

相關問題