有沒有辦法重新加載選定的選項卡我知道有.load()函數。但它想要一個標籤索引,我似乎沒有看到一種方法來抓住選定的標籤ID。JQuery UI - 重新加載選定的選項卡?
回答
更新:在jQuery 1.9中,selected
選項重命名爲active
。請參閱attomman's answer.
要獲取當前選定的索引,請使用tabs('option','selected')
函數。
例如,如果你有一個按鈕#button
(和#tabs
元素製作成標籤),你想要得到的指標,做到以下幾點:
$("#button").click(function() {
var current_index = $("#tabs").tabs("option","selected");
});
這裏有一個演示:http://jsfiddle.net/sVgAT/
要回答標題所示,在jQuery的1.8的問題以及更早版本,你會怎麼做:
var current_index = $("#tabs").tabs("option","selected");
$("#tabs").tabs('load',current_index);
而在jQuery的1.9或更高版本,你會怎麼做:
var current_index = $("#tabs").tabs("option","active");
$("#tabs").tabs('load',current_index);
我設法得到這個工作,但現在加載第一個選項卡的兩倍,當它處於非活動狀態。如果任何人有任何更多的建議,將不勝感激。
您可以在上面看到,該請求向服務器發出兩次,但第一個請求成功,因此它取消了第二個請求。不知道這是否是一個問題..??但是我沒有被看到它在控制檯放心
constructor: (@element) ->
@tabIndex = 0
@tabs = @element.find('#tabs')
@tabs.tabs
spinner: "Loading.."
cache: false
ajaxOptions:
cache: false
error: (xhr, status, index, anchor) ->
$(anchor.hash).html "Couldn't load this tab. We'll try to fix this as soon as possible."
#add custom load to make sure they always reload even the current tab when clicked
@element.find('ul li a').click (e) =>
if @tabIndex is @tabs.tabs('option', 'selected')
@tabs.tabs 'load', @tabs.tabs('option', 'selected')
@tabIndex = @tabs.tabs('option', 'selected')
這應該是一個單獨的問題,所以人們可以正確回答:) – 2012-09-25 12:56:21
泗門確實有正確的答案,但這個現在已經因爲JQuery的UI 1.9
http://jqueryui.com/upgrade-guide/1.9/#deprecated-selected-option-renamed-to-active
棄用現在你可以使用「活躍」,而不是'選擇' 的
因此,代碼會看起來像:
var current_index = $("#tabs").tabs("option","active"); $("#tabs").tabs('load',current_index);
如果有人絆倒了這個問題,並像我一樣使用jQuery EasyUI的標籤,西門子上面的回答將不起作用。相反,刷新標籤,使用:
var tab = $('#tt').tabs('getSelected');
tab.panel('refresh');
哪裏tt
是通過
<div id="tt" class="easyui-tabs">
它確實適用於新版本Easy UI,謝謝 – JacobChan 2013-09-10 08:35:26
下載這個插件創建的Cookie中的選項卡組的id
:
http://plugins.jquery.com/cookie/
插入jQuery cookie到你的頁面
<script src="jquery.cookie.js"></script>
,並補充一點:
$(".tabs").click(function() {
//getter , get the active tab
var active = $("#tabs").tabs("option", "active");
$.cookie("tabs_selected", active);
});
var cookieValue = $.cookie("tabs_selected");
// setter, set the active tab stocked
$("#tabs").tabs("option", "active",cookieValue);
- 1. Jquery UI選項卡只重新加載選項卡內容
- 2. Jquery-UI選項卡:雙重加載默認選項卡
- 3. jquery選項卡重新加載
- 4. jquery-ui選項卡 - 添加選項卡
- 5. 如何重新加載選定的選項卡jquery
- 6. 如何停止重新加載jQuery UI選項卡內的SWF
- 7. 帶有AJAX的jQuery UI選項卡 - 每次切換選項卡時強制重新加載選項卡內容
- 8. jquery ui ajax選項卡 - 重新加載選項卡,或更改選項卡的位置?
- 9. JQuery UI選項卡 - 加載AJAX選項卡內容
- 10. jQuery UI選項卡,加載錯誤
- 11. jQuery-UI選項卡 - 只加載一次
- 12. Jquery選項卡:打破創建 - 選擇 - 重新加載循環
- 13. jquery ui選項卡 - 在加載事件中獲取加載選項卡
- 14. 在Android的重新加載選項卡
- 15. JQuery UI選項卡重新加載頁面。而不是顯示所選選項卡
- 16. jQuery UI選項卡 - 鏈接選項卡
- 17. jQuery UI選項卡:多組選項卡
- 18. jQuery UI選項卡選擇
- 19. 選項卡和頁面重新加載
- 20. jQuery UI選項卡 - 獲取加載了Ajax的選項卡的URL
- 21. jQuery UI選項卡:如何在不重新加載的情況下切換到(ajax)選項卡?
- 22. 類似瀏覽器的選項卡 - jquery UI選項卡定位
- 23. jquery選項卡重新加載按鈕點擊內容
- 24. Bootsrap Twitter選項卡 - 頁面重新加載時轉到特定選項卡
- 25. 在JQuery UI選項卡上單擊刷新選項卡內容
- 26. jquery選項卡ui 1.10選項卡刷新
- 27. 重新加載jquery選項卡導致重複事件觸發
- 28. 在彈出的父窗口中重新加載jquery ui選項卡
- 29. jquery選項卡 - 在當前選項卡中加載url?
- 30. 如何在表單提交中重新加載jquery選項卡?
所以你的問題實在是如何讓所選擇的選項卡的索引? – 2010-08-08 14:36:41
這會解決我的問題,是的。 – Renari 2010-08-08 17:29:38