gpt4 book ai didi

javascript - 如何将 document.cookie 替换为 Cookies.set (使用最新的 jquery cookie 插件)

转载 作者:行者123 更新时间:2023-12-03 09:39:17 26 4
gpt4 key购买 nike

我试图将 document.cookie 替换为 Cookies.set (使用最新的 jquery cookie 插件)但不起作用。插件链接 here

    <script>

function setCookie(name,value,exdays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate() + exdays);
var value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
document.cookie=name + "=" + value;
}

function getCookie(name)
{
var i,x,y,ARRcookies=document.cookie.split(";");
for (i=0;i<ARRcookies.length;i++)
{
x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
x=x.replace(/^\s+|\s+$/g,"");
if (x==name)
{
return unescape(y);
}
}
}
</script>

最佳答案

这是等效的:

<script>

function setCookie(name,value,exdays) {
Cookies.set( name, value, {
expires: exdays,
// path: "" or
// path: "/"
// In version 2 the path is default to "/"
// In version <= 1 the path is default to "" (path of the current page)
})
}

function getCookie(name) {
return Cookies.get( name );
}
</script>

关于javascript - 如何将 document.cookie 替换为 Cookies.set (使用最新的 jquery cookie 插件),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31234507/

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