简体   繁体   中英

not able to set a cookie using jquery

I am trying to set a cookie using the following code using jquery and qtip. As you can see, when this 'beforeShow' event is triggered I need to set a cookie. I can confirm the event is being triggered as I see the alert although I'm not able to see the cookie being set? Should this code work or am I missing something?
Many thanks,

        api: {
            beforeShow: function() {
                if(document.getElementById('CheckMessage')) {
                    alert("");
                    $.cookie("MyTestExampleCookie", "1");
                    return false;
                }
            }
        },

Did you install jQuery cookie?

https://github.com/carhartl/jquery-cookie

You don't need a cookie unless you need to remember the value after the user has navigated away from the page. If you just want to know if a particular event has been triggered, set a normal variable.

If you do need to use cookies and manipulate these client-side, it is easier with a plugin as suggested above (but not absolutely necessary).

document.cookie = ("MyTestExampleCookie=1");

虽然使用一些cookie lib更合适

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM