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

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

问题描述



自从jQuery UI的1.9版本以来,他们使用<$ c贬值,这是一个开放式的问题, $ c> cookie 选项,以便保存跨多个页面的选项卡的活动状态。 http://jqueryui.com/upgrade-guide/1.9/#deprecated-cookie-option



我还没有看到任何其他文档,如何完成这个!所以我离开了抓头。



我最好的猜测是使用某种事件创建一个cookie,然后加载cookie?或者是否有其他方法可以通过多个网页和用户偏好来保存标签的有效状态?

解决方案

今天咬我。以下是似乎有效的方法:


  1. 使用jquery.cookie外挂程式( https://github.com/carhartl/jquery-cookie )(此步骤不是必需的,但它使生活更容易处理cookie)

  2. 使用以下代码片段:

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


这会设置一个名为activetab 10天后过期(有关更多选项,请参阅 jquery.cookie文档)记住每当任何选项卡被点击时当前选择的选项卡。在初始化时读取此cookie以显示最后保存的选项卡。第一次访问该网页时,标签页将被折叠。


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

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.

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. 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
            });
        }
    });
    

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天全站免登陆