jquery 生成随机数,怎样与结合cookie读取呢?就是让刷新不会改变(请看以下问题补充)
答案:2 悬赏:80
解决时间 2021-01-07 04:25
- 提问者网友:原来太熟悉了会陌生
- 2021-01-06 21:19
jquery 生成随机数,怎样与结合cookie读取呢?就是让刷新不会改变(请看以下问题补充)
最佳答案
- 二级知识专家网友:山君与见山
- 2021-01-06 22:42
复制过去直接运行吧
全部回答
- 1楼网友:英雄的欲望
- 2021-01-07 00:15
cookie对于IE浏览器可以直接访问,对于谷歌内核类似的浏览器要开启服务器访问。
// writeCookie("myCookie", "my name", 24);
// Stores the string "my name" in the cookie "myCookie" which expires after 24 hours.
// The hours parameter is optional; if hours is left out, the cookie value expires at the end of the visitor's browser session.
function writeCookie(name, value, hours)
{
var expire = "";
if(hours != null)
{
expire = new Date((new Date()).getTime() + hours * 3600000);
expire = "; expires=" + expire.toGMTString();
}
document.cookie = name + "=" + escape(value) + expire;
}
// Example:
// alert( readCookie("myCookie") );
function readCookie(name)
{
var cookieValue = "";
var search = name + "=";
if(document.cookie.length > 0)
{
offset = document.cookie.indexOf(search);
if (offset != -1)
{
offset += search.length;
end = document.cookie.indexOf(";", offset);
if (end == -1) end = document.cookie.length;
cookieValue = unescape(document.cookie.substring(offset, end))
}
}
return cookieValue;
}追问不要复制些没用的东西上来回答,针对问题回答。追答两个方法:一个写cookie,一个读cookie,难道你还看不懂么????要知道你这么菜,我就不回答你的问题了
// writeCookie("myCookie", "my name", 24);
// Stores the string "my name" in the cookie "myCookie" which expires after 24 hours.
// The hours parameter is optional; if hours is left out, the cookie value expires at the end of the visitor's browser session.
function writeCookie(name, value, hours)
{
var expire = "";
if(hours != null)
{
expire = new Date((new Date()).getTime() + hours * 3600000);
expire = "; expires=" + expire.toGMTString();
}
document.cookie = name + "=" + escape(value) + expire;
}
// Example:
// alert( readCookie("myCookie") );
function readCookie(name)
{
var cookieValue = "";
var search = name + "=";
if(document.cookie.length > 0)
{
offset = document.cookie.indexOf(search);
if (offset != -1)
{
offset += search.length;
end = document.cookie.indexOf(";", offset);
if (end == -1) end = document.cookie.length;
cookieValue = unescape(document.cookie.substring(offset, end))
}
}
return cookieValue;
}追问不要复制些没用的东西上来回答,针对问题回答。追答两个方法:一个写cookie,一个读cookie,难道你还看不懂么????要知道你这么菜,我就不回答你的问题了
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯