2009-08-06 28 views
1

好吧,我有地圖的國家的,對他們的狀態中,用戶點擊,和一幫供應商通過jQuery的通過頁面加載這樣的:的jQuery加載的數據不點火模式像它應該

$('#sa').click(function() { 
    $('#mapimg').hide(); 
    $('<div id="info">&nbsp;</div>').load('dealers.php?state=sa', function() { 
    $(this).hide() 
     .appendTo('#dealers') 
      .slideDown(3000); 
     }); 

然後,當它顯示交易時,我希望用戶能夠點擊每個經銷商旁邊的'聯繫我們',並通過其中的聯繫表單進行模態跳轉。但它似乎並沒有被解僱。點擊只是無所作爲。

這裏是jQuery代碼來觸發模態對話框:

$(document).ready(function() { 

//select all the a tag with name equal to modal 
    $('a').click(function(e) { //I have tried everything here, div, a[name=something], li, etc 
    //Cancel the link behavior 
    e.preventDefault(); 

    //Get the A tag 
    var id = $(this).attr('href'); 

    //Get the screen height and width 
    var maskHeight = $(document).height(); 
    var maskWidth = $(window).width(); 

    //Set heigth and width to mask to fill up the whole screen 
    $('#mask').css({'width':maskWidth,'height':maskHeight}); 

    //transition effect  
    $('#mask').fadeIn(1000);  
    $('#mask').fadeTo("slow",0.8); 

    //Get the window height and width 
    var winH = $(window).height(); 
    var winW = $(window).width(); 

    //Set the popup window to center 
    $(id).css('top', winH/2-$(id).height()/2); 
    $(id).css('left', winW/2-$(id).width()/2); 

    //transition effect 
    $(id).fadeIn(2000); 

}); 

//if close button is clicked 
$('.window .close').click(function (e) { 
    //Cancel the link behavior 
    e.preventDefault(); 

    $('#mask').hide(); 
    $('.window').hide(); 
});  

//if mask is clicked 
$('#mask').click(function() { 
    $(this).hide(); 
    $('.window').hide(); 
}); 

});

以下代碼在加載的內容之外工作,但不在裏面。任何人有任何想法?

<a href='#dialog2' class='openmodal'>Open Modal Box</a> 

THanks提前!

回答

2

您只需要動態加載內容即可使用活動綁定。請使用jQuery live events。假設接觸環節都有類「clsContact」,那麼你可以把對話框打開登錄界面,在功能「OpenModal」和綁定鏈接是這樣的:

$("a.clsContact").live('click', OpenModal); 
+0

偉大的工作。謝謝!只是一個側面說明:直到jQuery v1.3之前,live才能實現......這讓我暫時陷入了一陣子,但是最終得到了它的排序=] – Ryan 2009-08-11 08:27:07