简体   繁体   English

jQuery Cookie插件,检查cookie是否未设置

[英]Jquery Cookie plugin, check to see if cookie is unset

So Im using the jquery cookie plugin and I need to check if a cookie is unset. 因此,我正在使用jquery cookie插件,我需要检查cookie是否未设置。 I set it up something like this: 我将其设置如下:

if ($.cookie('language')==null) { 


}

This doesn't seem to work. 这似乎不起作用。 Any ideas why? 有什么想法吗?

简单使用:

if($.cookie("language")){}

To see what the plugin is returning, do a console.log() call: 要查看插件返回的内容,请执行console.log()调用:

console.log($.cookie("language"));

This should tell you what is being returned from the plugin if you monitor your Inspector / Firebug console. 如果您监视Inspector / Firebug控制台,这应该告诉您插件返回了什么。

I think you can get away with just doing if($.cookie("language")) but you'll have to test that. 我认为您可以仅通过if($。cookie(“ language”))来解决问题,但是您必须对此进行测试。

Line #90 in the source looks like that SHOULD be the result you want. 源代码中的第90行看起来应该是您想要的结果。 Check for any errors and test what happens if the cookie is set. 检查是否有任何错误,并测试是否设置了cookie。

https://github.com/carhartl/jquery-cookie/blob/master/jquery.cookie.js https://github.com/carhartl/jquery-cookie/blob/master/jquery.cookie.js

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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