2011-11-21 42 views
2

這裏是我想要做的事 - 我正在寫通用的疊加功能,將服務於特定類別的所有環節。這很簡單,雖然,你有一個像這樣的鏈接:jQuery的工具疊加在第二次點擊不顯示

<a class="modalInput" rel="#prompt">Local load</a> 

,當你點擊它,在javascript踢:

 $(".modalInput").live("click",function() 
    { 
     var obj = null; 
     obj = $(this); 
     var container = null; 
     if (!(typeof obj.attr("container") === 'undefined')) 
     { 
      container = obj.attr("container"); 
     } 
     else 
     {    
      if (typeof obj.attr("container") === 'undefined') 
      { 
       container = obj.attr("rel"); 

       if (container == '#norel') 
       { 
        container = randomString(); 
        $("#footer").append("<div id='"+container+"' class='gru_curtain_simple_overlay'></div>");     
        obj.attr("container", container); 
       } 
       else 
       { 
        container = container.substring(1, container.length); 
       } 
      } 
     } 

     test_test(container, obj); 
    }); 

該功能獲取的該鏈接的各種參數,並決定它應該做什麼。然後,調用test_test(),如下所示:

function test_test(container, obj) 
{ 
    var triggers = jQuery("#"+container).overlay({ 

     // some mask tweaks suitable for modal dialogs 
     mask: { 
      color: '#000', 
      loadSpeed: 200, 
      opacity: 0.9 
     }, 
     closeOnClick: false, 
     closeOnEsc: true, 
     load: true, 
     oneInstance: false, 

     onBeforeLoad: function() { 
      if ($.trim($("#"+container).html()).length < 25) 
      { 
       //Check if it's remote 
       var remote = obj.attr("remote");      
       if (!(typeof remote === 'undefined')) 
       { 
        //$(container).load(remote); 
        $.get(remote, function(data) 
        { 
         $("#"+container).empty().append(data); 
        }); 
       } 
      } 

      //Check if dialog should have close button 
      var is_closable = obj.attr("closable"); 
      if (is_closable) 
      { 
       $("a.close").hide(); 
      } 

      var wd = parseInt(obj.attr("wd")); 
      var hg = parseInt(obj.attr("hg")); 

      if (!(typeof wd === 'undefined')) 
      { 
       $("#"+container).css("width", wd); 
      } 
      if (!(typeof hg === 'undefined')) 
      { 
       $("#"+container).animate({ 
        height: hg 
       }, 800, function() 
       { 
        $("#"+container).css("overflow-x", "hidden"); 
        $("#"+container).css("overflow-y", "visible"); 

       }); 
       //$(container).css("height", hg); 
      } 
     }, 

     onLoad: function() {    
     }, 

     onClose: function() { 
      //Destroy current container 
      //var container = obj.attr("rel"); 
      //$(container).empty().html('<img src="/wp-content/themes/default/images/preloader.gif" style="margin: 25% 25%; width: 120px;"/>'); 
     } 
    }); 

我知道,它很大,但它工作得很好。那麼問題是什麼?如果我點擊鏈接,它會首次顯示覆蓋圖。但是當我再次點擊它時,它不起作用。它沒有提供任何錯誤,沒有任何警告,基本上它應該可以工作,但它不會。

我已嘗試越過我的腦海(如減少test_test()函數,這是基本的),但沒有做的伎倆一切。所以我沒有想法,如果有人有建議,我願意傾聽。

編輯:我發現,如果我有這樣的另一個鏈接:

<a class="modalInput" rel="#norel" remote="/test?t=694749&inner=1" wd="850" hg="500">Remote load</a> 

我可以點擊這個鏈接,就像我想的(這一個創建它在頁腳附加隨機的div),但後上面的鏈接(其中有集裝箱某處HTML,因此不會產生任何東西),所有覆蓋沒有顯示了。

+0

您是否嘗試過殺死點擊處理程序,如:$(「 modalInput‘)死(’點擊‘)生活(’點擊」,函數()... [jQuery的工具警報作品 – madc

+0

可能重複一次。 (但只有一次)](http://stackoverflow.com/questions/4567947/jquery-tools-alert-works-once-but-only-once) –

+0

@Andrew惠特克是,問題是相同的,但該解決方案不適合我,因爲我的容器並不總是一樣的。我可以有無限數量的隨機生成的容器應該覆蓋,這就是爲什麼我傳遞「容器」參數。 –

回答

4

像安德魯惠特克說,該解決方案示於 jQuery Tools alert works once (but only once)

包裹起來:刪除「負載:真」從覆蓋參數,可以手動調用.load()。

工作多次:

//call the overlay 
$('#idofoverlay').overlay({ 
// load: true 
}).load(); 

只有一次工作:

//call the overlay 
$('#idofoverlay').overlay({ 
    load: true 
}); 

缺點:

  • 與jQuery的工具疊加一起,你鬆散的 「關閉」 項 時所謂這樣
相關問題