首页 > 代码库 > JS Cookie

JS Cookie

function SetCookieFun(name, value)//两个参数,一个是cookie的名子,一个是值! 存入cookie
{
    var exp = new Date();    //new Date("December 31, 9998");  保存30分钟
    exp.setTime(exp.getTime() + 30 * 60 * 1000);
    document.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString();
}
function getCookieFun(name)
{
var arr = document.cookie.match(new RegExp("(^| )" + name + "=([^;]*)(;|$)")); if (arr != null) return unescape(arr[2]); return null; } //清空所有的cookie function clearAllCookie() { var keys = document.cookie.match(/[^ =;]+(?=\=)/g); if (keys) { for (var i = keys.length; i--;) document.cookie = keys[i] + =0;expires= + new Date(0).toUTCString() } }

 

JS Cookie