私はこのjqueryコードを持っています:
<script type="text/javascript">
$(document).ready(function() {
$(".tabLink").each(function(){
$(this).click(function(){
tabeId = $(this).attr('id');
$(".tabLink").removeClass("activeLink");
$(this).addClass("activeLink");
$(".tabcontent").addClass("hide");
$("#"+tabeId+"-1").removeClass("hide")
return false;
});
});
});
</script>
このコードを使用してページが更新された場合にタブが記憶されるようにしようとしています:
<script type="text/javascript">
$(document).ready(function() {
$(".tabLink").each(function(){
$(this).click(function(){
localStorage.selectedTab = $(this).index() + 1;
tabeId = $(this).attr('id');
$(".tabLink").removeClass("activeLink");
$(this).addClass("activeLink");
$(".tabcontent").addClass("hide");
$("#"+tabeId+"-1").removeClass("hide")
return false;
});
});
// search for local storage
if (localStorage.selectedTab) {
$(".tabLink:eq(" + (localStorage.selectedTab - 1) + ")").click();
}
});
</script>
HTML:
<div class="tab-box">
<a href="javascript:;" class="tabLink activeLink" id="viewcustomer">View Customer</a>
<a href="javascript:;" class="tabLink activeLink" id="viewresellercustomers">View Reseller Customer</a>
<a href="javascript:;" class="tabLink activeLink" id="viewsalesmancustomer">View Salesman Customer</a>
<a href="javascript:;" class="tabLink" id="archivedcustomers">View Archived Customer</a>
</div>
<div class="tabcontent" id="viewcustomer-1">
content...
</div>.....
正常に動作しますが、タブは複数のページにあるため、別のページに移動すると、最後に選択したタブを記憶しようとして別のタブが選択されます。
各ページで最後に選択したタブを記憶させるにはどうすればよいですか?