2010-06-21 31 views
0

每當打開手風琴選項卡以獲取該選項卡的內容時,我都想要啓動ajax調用。爲此,我需要知道什麼標籤留下,哪些標籤打開。 從jQuery文檔:從jquery.ui.accordion獲取新舊內容的ID

$('.ui-accordion').bind('accordionchange', function(event, ui) { 
    ui.newHeader // jQuery object, activated header 
    ui.oldHeader // jQuery object, previous header 
    ui.newContent // jQuery object, activated content 
    ui.oldContent // jQuery object, previous content 
}); 

在Firebug我可以看到我需要的是ui.newContent或ui.oldContent。
這些似乎是真正的div,所以我不知何故需要得到他們的id。

function OnAccordionChanged(event, ui) { 
    //get the id of the old tab 
    var oldId = ui.oldContent.id; 

    //apply (business) filters 
    //get the id of the new tab 
    //fetch the content 
    //append to new tab 
    //party 
} 

它基本上是檸第一步,我會失敗:■

回答

0

您通過

my_object.attr("id") 
1

似乎有實際上是一個錯誤或東西得到(jQuery的)DOM對象的ID newContent會給你'undefined'但是newHeader會給你

$(ui.newHeader).attr('id')會給出h3標籤的ID $(ui.newContent).attr('id')應該給div的id,但不是。相反,它提供'undefined',即使只是ui.newContent.attr('id')這應該是確定stil給出未定義。在Firebug使用DOM選項卡我能確定一個奇怪的,不恰當的工作圍繞

ui.newContent.prevObject.attr('id') 

看來,DIV實際上ui.newContent.prevObject這是一個jQuery對象是......似乎完美的工作