1. 程式人生 > >JS Cookie

JS Cookie

pan null ret document var get expire style class

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