2011-08-06 31 views
1

我想用一個jQuery插件來實現展開所有Divs /摺疊所有Divs /展開或摺疊個別Divs,這裏是jquery插件:http://www.adipalaz.com/experiments/jquery/multiple_expand_all_collapse_all.html。唯一不同的是我試圖將這些效果應用到從AJAX post檢索到的Div。jquery切換失敗的數據檢索從Ajax Post

下面是我的電流:

數據發佈到一個URL(訪問getdata.php)fromindex.php和檢索的Html DIVs->執行了div切換。已經在Index.PHP上加載了te DIV所需的CSS。

切換按鈕是使用jQuery和CSS附加到索引頁上的檢索的DIV。切換div所需的java腳本已存在於index.php頁面中。但切換按鈕不會出現在檢索到的div上,因爲即使在檢索內容之前它們也會被觸發。我嘗試使用ajaxStop,觸發ajax完成,然後觸發切換功能,但沒有use.below是我的示例代碼。

 $.ajax({ 
           type: 'POST', 
           url: 'getTicketSummary.php', 
           data: {ref_no: ref_no}, 
           success: function(data) { 
            $('#wrapper').hide().html(data).slideDown('slow'); 
            $(function() { 
    $("#content h3.expand").toggler(); 
     $("#content div.demo").expandAll({trigger: "h3.expand", ref: "h3.expand"}); 
    }); 
          } 
         }); 
        } 
       }); 

$(function() { 
    $("#content h3.expand").toggler(); 
     $("#content div.demo").expandAll({trigger: "h3.expand", ref: "h3.expand"}); 
    }); 

//這是我的切換功能,爲正在使用jQuery插件,expand.js,現在我嘗試添加Post請求後的功能,但它合乎理似乎工作。

回答

1

下面的代碼就足夠了這個

$.ajax({ 
     type: 'POST', 
     url: 'getTicketSummary.php', 
     data: {ref_no: ref_no}, 
     success: function(data) { 
       $('#wrapper').hide().html(data).slideDown('slow',function(){ 
        $("#content h3.expand").toggler(); 
        $("#content div.demo").expandAll({trigger: "h3.expand", ref: "h3.expand"}); 
       }); 
     } 
    }); 
+0

@chamika ..非常感謝兄弟這一工程般的魅力,避免使用額外的語句觸發的需要。 –

1

沒關係,

我想了一下。我使用$('#wrapper')。ajaxStop觸發ajax請求的完成,並觸發一個函數來啓用完成時的切換。

我的代碼是

$.ajax({ 
           type: 'POST', 
           url: 'getTicketSummary.php', 
           data: {ref_no: ref_no}, 
           success: function(data) { 
            $('#wrapper').hide().html(data).slideDown('slow'); 
            $(function() { 
    $("#content h3.expand").toggler(); 
     $("#content div.demo").expandAll({trigger: "h3.expand", ref: "h3.expand"}); 
    }); 
          } 
         }); 
        } 
       }); 

$('#wrapper').ajaxStop(function() { 
    $("#content h3.expand").toggler(); 
     $("#content div.demo").expandAll({trigger: "h3.expand", ref: "h3.expand"}); 
    }); 

希望這有助於有人有類似的問題,謝謝!