2013-01-14 2 views
1

내가 가지고이 일을 내 탭 : "현재"탭 새로 고침 페이지 뒤에 표시되도록jQuery를 쿠키 새로 고침

$('.tabed .tabs li:first-child').addClass('current'); 
$('.tabed .block:first').addClass('current'); 

$('.tabed .tabs li').click(function(){ 
     var tabNumber = $(this).index(); 
     $(this).parent('ul').siblings('.block').removeClass('current'); 
     $(this).siblings('li').removeClass('current'); 
     $(this).addClass('current'); 
     $(this).parent('ul').parent('.tabed').children('.block:eq('+ tabNumber +')').addClass('current'); 
}); 

어떻게 내가 거기에 jQuery를 쿠키 플러그인을 구현할 수있다? 그러나 당신이 인덱스를 기반으로 동일한 기능을 수행 할 수 있도록

답변

1

내가 탭의 ID를 기반으로 이렇게 당신이 원하는 경우 :

$(document).on("click", "#tabs > li", function(){ 
    if(this.id) 
     $.cookie("tab", this.id); 
});  

if($.cookie("tab")) 
{ 
    $("#"+$.cookie("tab")).addClass('active'); 
    $("#"+$.cookie("tab")+"content").addClass('active'); 
} 
else 
{ 
    $('.tabbable > .nav-tabs > :first-child').addClass('active'); 
    $('.tab-content > :first-child').addClass('active'); 
} 
0

나는 당신이 이것을 달성하기 위해 jQuery를 쿠키 플러그인을 필요가 있다고 생각하지 않습니다 .

당신이 해시에서 현재 탭의 인덱스를 설정하려고하면 무엇 :

$(".tabed .tabs li").on("click", function() { 
    /* ... Your stuff here ... */ 
    window.location.hash = tabNumber; 
}); 

if (window.location.hash) { 
    var tabId = parseInt(window.location.hash.split("#")[1]); 

    $(".tabed .tabs li:nth-child(" + (tabId - 1) + ")").addClass("current"); 
} 
+0

니스 개념을, 그러나 그것은 일을 가져올 수 없습니다. 해시를 추가하지만 새로 고칠 때 현재 탭을 유지하지 않습니다. 오류도 없습니다. – Andrew

관련 문제