JQuery UI选项卡:具有多个选项卡的Cookie持久性

Mar*_*uth 0 jquery-ui jquery-ui-tabs

嘿,我有一些代码,用于连接Jquery UI选项卡的Ready函数中的选项卡

// wireup tabs
$(".tabs").tabs({
    cookie: {
        expires: 30
    }
});
Run Code Online (Sandbox Code Playgroud)

这很好用,除了选项卡索引保持在所有选项卡位置之外(因为我使用.tabs选择器一次连接所有选项卡).有没有办法将cookie名称自动连接到与选择器匹配的不同foreach找到的项目?

Mar*_*uth 5

$(this)是指在上述情况下运行此文档时的文档.但是,在每个函数中运行连接,允许直接访问项目,然后我们可以访问属性(例如HTML中用于连接cookie的特殊属性).我使用了tab id,如果该属性不存在,则默认为自命名.

// wireup tabs
$(".tabs").each(function() {
    var tabid = $(this).attr("tabid");
    if (tabid == undefined || tabid == null || tabid == "") {
        $(this).tabs({
            cookie: {
                expires: 30
            }
        });
    }
    else {
        $(this).tabs({
            cookie: {
                expires: 30,
                name: tabid
            }
        });
    }
});
Run Code Online (Sandbox Code Playgroud)