[英]jQuery Cookie - update the value
I am using jQuery cookie library. 我正在使用jQuery cookie库。 I need create a cookie and if the cookie exists to update the value.
我需要创建一个cookie,如果存在cookie来更新值。 How can I do this?
我怎样才能做到这一点?
if ($.cookie('checkID') == null {
var getHost = getHostname.hostname;
switch (getHost) {
case 'www.google.com':
var GetParamID = 'Abc1';
break;
case 'www.yahoo.com':
var GetParamID = '345Cdv';
break;
default:
var GetParamID = '';
$.cookie('checkID', GetParamID , { path: '/' });
}
You're missing a ")" in the first line of code, and you should check for undefined (see here ) as in jQuery Cookie documentation ( https://github.com/carhartl/jquery-cookie ). 您在代码的第一行中缺少“)”,并且应该像jQuery Cookie文档( https://github.com/carhartl/jquery-cookie )中那样检查未定义的内容(请参阅此处 )。 Other than that, your code should work.
除此之外,您的代码应该可以工作。 Be aware that if your cookie has been previously set in a different path than "/", you will have two different cookies (see: How to handle multiple cookies with the same name? )
请注意,如果您先前已将cookie设置为与“ /”不同的路径,那么您将拥有两个不同的cookie(请参阅: 如何处理具有相同名称的多个cookie? )
if (typeof ($.cookie('checkID')) === "undefined") {
var getHost = getHostname.hostname;
switch (getHost) {
case 'www.google.com':
var GetParamID = 'Abc1';
break;
case 'www.yahoo.com':
var GetParamID = '345Cdv';
break;
default:
var GetParamID = '';
$.cookie('checkID', GetParamID , { path: '/' });
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.