需要帮助创建Cookie [英] Need Help in Creating a Cookie

查看:123
本文介绍了需要帮助创建Cookie的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为的按钮和另一个名为按钮。

I have a button named yes and another named no.

<input type="button" name="yes" onclick="button()">
<input type="button" name="no">

我要在点击 yes 时创建一个Cookie,信息是,需要在7天后过期。我怎么做?

I want to create a cookie when yes is clicked that would store the info "YES" and needs to expire after 7 days. How do i do that? The only information that the cookie needs to store is "YES".

推荐答案

您可以使用 document.cookie

var expDate = new Date();
expDate.setDate(expDate.getDate() + 7);
document.cookie = 'your_cookie_name=YES;expires=' + expDate.toUTCString();

或者如果你使用jquery,你可以看一下 Cookie插件。以下是示例

Or if you are using jquery you may take a look at the Cookie plugin. Here's an example.

这篇关于需要帮助创建Cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆