Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/73.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何设置cookie';js的过期日期是多少?_Javascript_Html_Cookies - Fatal编程技术网

Javascript 如何设置cookie';js的过期日期是多少?

Javascript 如何设置cookie';js的过期日期是多少?,javascript,html,cookies,Javascript,Html,Cookies,这是我的剧本 函数save(){ var x=document.getElementById(“用户”).value; var y=document.getElementById(“密码”).value; document.cookie=x+“”+y; } 函数写入(){ document.write(document.cookie); } 添加最大年龄段: ;max-age=<max-age-in-seconds> 我建议使用库来设置Cookie,因为跨浏览器设置/读取Co

这是我的剧本


函数save(){
var x=document.getElementById(“用户”).value;
var y=document.getElementById(“密码”).value;
document.cookie=x+“”+y;
}
函数写入(){
document.write(document.cookie);
}
添加最大年龄段:

 ;max-age=<max-age-in-seconds>
我建议使用库来设置Cookie,因为跨浏览器设置/读取Cookie时会遇到很多问题

注意:在cookie中存储明文密码是不好的做法。您可能正在寻找会话cookie。

这是来自的一个示例


你只需要写

document.cookie = "cookiename=value; expires= 03 Dec 2015 00:00"
但是,如果您只是在Google上键入“javascript cookies”,您可以找到以下页面:
它非常有用

看看这个问题[1],它应该对你有帮助。[1]:
document.cookie="cookiename=cookievalue; expires=Thu, 18 Dec 2013 12:00:00 UTC";
document.cookie = "cookiename=value; expires= 03 Dec 2015 00:00"