<script>
alert("cookie before= " + document.cookie);
function addCookie(objName,objValue,objHours)
{
var str = objName + "=" + escape(objValue);
if(objHours > 0)
{
//为0时不设定过期时间,浏览器关闭时cookie自动消失
var date = new Date();
var ms = objHours*3600*1000;
date.setTime(date.getTime() + ms);
str += "; expires=" + date.toGMTString();
}
document.cookie = str;
alert("添加cookie成功");
}
addCookie("lang","zh_CN",100);
alert("cookie after= " + document.cookie);
</script>
js cookie
最新推荐文章于 2024-06-19 13:32:48 发布