2011-11-30 41 views
1

我有2頁:index.php和form1.php。 在我的index.php我有一個按鈕,它具有功能加載在DIV form1.php的內容:jquery ui風格不顯示時加載內容上ajax

$("#btnLoadContent").button().click(function(){ 
$("#divcontent").empty().load("form1.php")}); 

在form1.php y的一種形式,一個名爲btnSend按鈕。 在指數我使用這個:

$("#btnSend").button(); 

但加載時,這個按鈕沒有實現的腳本的風格或功能。我還沒有意識到爲什麼。

+0

代碼似乎並不正確,嘗試張貼滿糾正代碼更accurancy –

回答

0

我找到了答案。

只是嘗試這樣的代碼

$("#btnLoadContent").button().click(function(){ 
    $.ajax({ 
     url:"form1.php", 
     success:function(data){ 
      $("#divcontent").empty().append(data); 
      $("#btnSend").button(); 
     } 
    }); 
}); 
1

您可能需要在jQuery中使用live函數。另外,如果加載ajax的內容位於iframe內,則需要再次從加載的站點內調用樣式。

1

我認爲當index.php加載時,.button()已經被執行。在form1.php加載後它不會再執行。 .load()函數有一個回調參數,將在內容加載後執行。您應該將$("#btnSend").button()添加到該回調函數中。

例如:

$("#divcontent").empty().load('form1.php', function(response, status, xhr) { 
    $("#btnSend").button(); 
});