记得整个网站pssed标签$ P $ [英] remember tab pressed across website

查看:145
本文介绍了记得整个网站pssed标签$ P $的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了自己的卡口与超链接和div的。 IM将它们放置在侧边栏中。

I have created my own tabs with hyperlinks and divs. im placing them within the sidebar.

使用im jquerys .show()和上点击一个hypelink时相关的div隐藏()。

im using jquerys .show() and hide() on relevant divs when a hypelink is clicked.

其做工精细,不过,我想最后一个环节/选项卡单击当用户浏览被整个网站记住。

its working fine, however, i would like the last link/tab clicked to be remembered across the site as the user navigates.

我怎样才能做到这一点?

how can i do this?

推荐答案

您最好的选择是使用一个Cookie存储活动标签的名称。然后,在页面加载,请与JS的饼干,并使用此为基础,显示出正确的选项卡,并隐藏其他。

Your best bet would be to use a cookie to store the name of the active tab. Then, on page load, check the cookie with JS and use this as the basis for showing the correct tab and hiding the others.

我会建议jQuery的cookie的插件设置和读取cookie:
http://plugins.jquery.com/project/Cookie

I would recommend the jQuery cookie plugin for setting and reading cookies: http://plugins.jquery.com/project/Cookie

您code可能是这个样子(速写,所以可能没有语法错误):

Your code may look something like this (quick sketch, so may not be free of syntax errors):

MARKUP

<ul id="tabs">
  <li id="tab-a">First tab</li>
  <li id="tab-b">Second tab</li>
  <li id="tab-c">Third tab</li>
</ul>

JAVSCRIPT

JAVSCRIPT

//On Window load:
if ($.cookie('activetab')) {
  var activetabId = $.cookie('activetab');
  $('#tabs li').removeClass('active');
  $('#'+activetabId).addClass('active');
}

//On tab click
$('#tabs li')click(function(){
 var id =  $(this).attr('id');
 $.cookie('activetab',id);
});

这篇关于记得整个网站pssed标签$ P $的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆