更改此函数,使 cookie 过期为 30 秒

发布于 2024-12-06 06:09:27 字数 304 浏览 3 评论 0原文

我怎样才能更改此功能以使其过期而不是 30 秒内过期?,我对此一无所知..它来自 Telerik

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

How can I change this function to expire instead of days in 30 seconds?, I have no idea about this.. and its from Telerik

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

往日情怀 2024-12-13 06:09:27

您可以使用 valueOf 函数:

var numberOfSeconds = 30;
var exdate = new Date(new Date().valueOf() + 1000 * numberOfSeconds);

You could use the valueOf function:

var numberOfSeconds = 30;
var exdate = new Date(new Date().valueOf() + 1000 * numberOfSeconds);
帅气称霸 2024-12-13 06:09:27

使用 getSeconds 代替 .getDate().setDate() (获取和设置月份中的某一天):

exdate = new Date(exdate.setSeconds(exdate.getSeconds()+30));

Instead of .getDate() and .setDate() (which get and set the day-of-the-month), use getSeconds:

exdate = new Date(exdate.setSeconds(exdate.getSeconds()+30));
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文