开发者

jQuery - Set all cookies ending with

I'm wondering if it's possible to use a wildcard to select multiple cookies. I'm using jQuery to save various scroll position and would like to clear them out in one go. At the moment I clear them out individually as below

    function clearScroll(elementID) {
    if ($.cookie) {
        $.cookie(elementID + '_scrollpos', 0);
    }
}

What I'd like is开发者_高级运维 a clear all something like below.

function clearAllScroll() {
    if ($.cookie) {
        $cookie([name$='_scrollpos'],0);
    }  
}

Is this possible?


Since there is no cookie magic built into jQuery, I assume your are using the cookie plugin.

This plugin does not have the feature you are asking for. As far as I can tell, it does not even provide a way to iterate existing cookies. There might be other plugins that provide this feature.

If you find that you often have to iterate cookies, and you cannot seem to find any plugin that lets you do that, consider rolling your own plugin - or extending an existing one. It really is quite easy to pack up functionality as jQuery plugins. See the source of the cookie plugin for an example of how it might look.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜