2012-03-14 84 views
0

據我所知,jQuery的標籤加載方法處理只有一個選項卡索引,如下:如何使用jQuery的標籤的加載方法加載多個標籤

.tabs("load" , index) 

試圖多次調用在繼承只取消先前的呼籲,即:

.tabs ("load", 2) 

.tabs ("load", 3) 

的tabIndex 2的負荷由tabindex屬性的後續加載取消3.

你怎麼能調用load方法沒有更早通話被後來的通話取消了嗎?

+1

你可以給你一些關於你想要達到什麼的更多細節。 – westo 2012-03-14 00:52:13

+0

您是否嘗試預加載在選項卡中的內容? – 2012-03-14 00:56:53

+0

@westo:我的應用程序需要在編輯其他選項卡上的某些字段時經常重新加載兩個選項卡。 – ivarrian 2012-03-14 03:30:28

回答

0

你已經差不多了。我使用這樣的方法和一些AJAX功能來即時添加標籤。

$("#nameOfMyTabsList").tabs("add", "#href-to-my-element"+some_unique_string, "This Is The Link Text!"); 

這將創建選項卡,並用的ID的DIV:

<div id="href-to-my-element"> 
    //this is where my text is. 
</div> 

阿賈克斯:

$.ajax({ 
url: 'location/to/my/file.php', 
data: 'data='+myDataVar, 
success: function(data){ 
    $("#nameOfMyTabsList").tabs("add", "#href-to-my-element"+some_unique_string, "This Is The Link Text!"); 
    $("#href-to-my-element"+some_unique_string).html(data); 
} 
}); 

Alright..we're差不多了,但如何做我創建了獨特的動態div?那麼,我們走吧:

$("#whatever").click(function(){ 
    //I had a list of elements, each one had it's own unique name, so I created a variable from my links text when I click. 
    var ourTabName = $(this).text; 
    //I did some regexp and replacing of unwanted values so there wasn't issues with &, -, and/operators 
    var cleanTabName = ourTabName(//do regexp); 
    //the data I needed to send to the server is held in my HREF tag. A replace of the hash tag and I'm good to go 
    var myDataVar = $(this).attr("href"); 
    //just a simple removal, nothing fancy 
    var myDataVar = myDataVar.replace(/#/g, ''); 
    //now I can do my ajax. all my variables are set. let's build the new tabs and inject the content. 
    $.ajax({ 
    url: 'location/to/my/file.php', 
    data: 'data='+myDataVar, 
    success: function(data){ 
     //This is where pure magic happens. See our cleanName? we're using it again for the dynamic ID tags and Links so we don't run into any issues. 
     $("#nameOfMyTabsList").tabs("add", "#href-to-my-element"+cleanTabName, "This Is The Link Text!"); 
     //now that the link and div have been created, we access the div with the same identifer we just made in the above line. then we append the data that was returned from our ajax request. 
     $("#href-to-my-element"+some_unique-string).html(data); 
    } 
    }); 
}); 

這是我用來創建動態標籤的解決方案。我並不是說它很漂亮(無論如何);但它是100%經過測試和驗證的解決方案。

+0

謝謝,但這似乎是添加新選項卡的代碼。我不想添加任何選項卡,我只需要使用load方法重新加載(或刷新)一些選項卡。該方案是:我有8個標籤鏈接到一些AJAX內容。我想重新加載tabindex 2和3(不管它們以前是否加載過)。希望這個信息有幫助。 – ivarrian 2012-03-14 03:35:26

+0

所以你真正想說的是,你需要將Tab2和Tab3的$ .ajax調用放入函數中,並在調用需要重新加載這些選項卡的事件時調用這些函數?讓我看看yarrrr Ajax調用。我會幫你的。 – Ohgodwhy 2012-03-14 04:02:32

+0

謝謝。這是我想要實現的。我有一個AJAX調用遠程資源,返回(除其他外)一個選項卡索引數組。然後我遍歷這個數組並「加載」這些選項卡。但是,加載方法發生的情況是,瀏覽器在移至第二個加載時取消第一個加載,等等。對於(I = 0;我 ivarrian 2012-03-14 04:12:27