추가 jquery.cookie.js 라이브러리와 다음 코드는
$(document).ready(function() {
var $tabs = $("#tabs").tabs({
activate: function(event ,ui){
$.cookie('active_tab', ui.newTab.index(), { path: '/' });
}
});
var selectedIndex=parseInt($.cookie('active_tab'));
if(selectedIndex) {
$tabs.tabs({ active: selectedIndex });
$('#tabs').find("ul:first li:nth-child(" + (selectedIndex + 1) + ")").find('a').trigger('click');
}
// set cookie on tab select
});
또는 jquery.cookie.js없이
,
var activeTab;
var $tabs = $("#tabs").tabs({
activate: function (event, ui) {
activeTab = ui.newTab.index();
}
});
var params = {};
if (location.search) {
var parts = location.search.substring(1).split('&');
for (var i = 0; i < parts.length; i++) {
var nv = parts[i].split('=');
if (!nv[0]) continue;
params[nv[0]] = nv[1] || true;
}
}
// Now you can get the parameters you want like so:
var selectedIndex = parseInt(params.selectedIndex);
if (selectedIndex) {
$tabs.tabs({
active: selectedIndex
});
$('#tabs').find("ul:first li:nth-child(" + (selectedIndex + 1) + ")").find('a').trigger('click');
}
$('#tabs').click(function() {
window.location.href = window.location.href.replace(/[\?#].*|$/, "?selectedIndex="+activeTab);
});
이 희망 작동 매개 변수로 활성 탭 인덱스를 전달합니다. 감사합니다.
사례 또는 링크를 제공해 주시기 바랍니다. 내 재판 : http://jsfiddle.net/CnEUh/500/, thanks @Sheremet. – user3684675