jquery ui 标签不再支持cookie?怎么办? [英] jquery ui tabs no longer supporting cookie? now what?

查看:22
本文介绍了jquery ui 标签不再支持cookie?怎么办?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于这是一个开放式问题,我深表歉意,但我不知所措.

I apologize for this being an open ended question, but I am at a loss.

从 1.9 版的 jquery UI 开始,他们使用 cookie 选项折旧,以保存跨多个页面的选项卡的活动状态.http://jqueryui.com/upgrade-guide/1.9/#deprecated-cookie-选项

Since version 1.9 of the jquery UI, they depreciated using the cookie option in order to save the active state of tabs across multiple pages. http://jqueryui.com/upgrade-guide/1.9/#deprecated-cookie-option

我现在还没有看到任何其他有关如何完成此操作的文档!所以我只能挠头了.

I haven't seen ANY other documentation out there on how to accomplish this now! So I am left scratching my head.

我最好的猜测是使用某种event来创建一个cookie,然后加载cookie?或者是否有其他方法可以跨多个页面并根据用户偏好保存选项卡的活动状态?

My best guess would be to use some sort of event to create a cookie, then load the cookie? Or is there some OTHER way to save the active state of the tabs across multiple pages and by user preference?

推荐答案

今天遇到了同样的问题.这是似乎有效的方法:

Had the same issue bite me today. Here is what seems to work:

  1. 使用 jquery.cookie 插件(https://github.com/carhartl/jquery-cookie)(这一步不是必需的,但它使处理 cookie 的生活更轻松)
  2. 使用以下代码片段:

  1. Use jquery.cookie plugin (https://github.com/carhartl/jquery-cookie) (This step is not necessary, but it makes the life easier dealing with cookies)
  2. Use the following code fragment:

$( ".selector" ).tabs({
    active   : $.cookie('activetab'),
    activate : function( event, ui ){
        $.cookie( 'activetab', ui.newTab.index(),{
            expires : 10
        });
    }
});

这会设置一个名为activetab"的 cookie,它会在 10 天后过期(请参阅 jquery.cookie文档 以获取更多选项)以在单击任何选项卡时记住当前选择的选项卡.在初始化时读取此 cookie 以显示上次保存的选项卡.第一次访问页面时,选项卡将被折叠.

This sets a cookie called "activetab" which expires after 10 days (refer to jquery.cookie documentation for more options) to remember the currently selected tab whenever any tab is clicked. This cookie is read at the initialization time to display the last saved tab. The first time the page is visited, the tabs will be collapsed.

这篇关于jquery ui 标签不再支持cookie?怎么办?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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