gpt4 book ai didi

javascript - 单击县旗时设置 cookie

转载 作者:行者123 更新时间:2023-11-29 22:05:46 25 4
gpt4 key购买 nike

当语言更改时,我试图在我的网站上设置一些 cookie,但它不起作用。

这是网站:http://www.goodyearwines.com/

这是我使用的代码:

function setCookies(name, value, expires, path, domain, secure){
document.cookie = name + "=" + escape(value) + "; ";

if(expires){
expires = setExpiration(expires);
document.cookie += "expires=" + expires + "; ";
}
if(path){
document.cookie += "path=" + path + "; ";
}
if(domain){
document.cookie += "domain=" + domain + "; ";
}
if(secure){
document.cookie += "secure; ";
}
}


$( "a.qtrans_flag_en" ).click(function() {
setCookies('thelanguage', 'eng', 3, '/', 'goodyearwines.com');
});

$( "a.qtrans_flag_zh" ).click(function() {
setCookies('thelanguage', 'chi', 3, '/', 'goodyearwines.com');
});

$( "a.qtrans_flag_fr" ).click(function() {
setCookies('thelanguage', 'fra', 3, '/', 'goodyearwines.com');
});

欢迎任何帮助。谢谢

最佳答案

document.cookie 不是一个简单的变量,附加到它可能不起作用。而是尝试使用这个:

function setCookies(name, value, expires, path, domain, secure){

var cookie = name + "=" + escape(value) + "; ";

if(expires){
expires = setExpiration(expires);
cookie += "expires=" + expires + "; ";
}
if(path){
cookie += "path=" + path + "; ";
}
if(domain){
cookie += "domain=" + domain + "; ";
}
if(secure){
cookie += "secure; ";
}

document.cookie = cookie;
}

并定义函数setExpiration()

关于javascript - 单击县旗时设置 cookie,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21074442/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com