cookie

//建立cookie

function setCookie(_name, _value, _date){

if( _date ){

var d = new Date();

d.setDate(d.getDate()+_date);

document.cookie = _name+"="+encodeURIComponent(_value)+"; path=/; expires="+d.toGMTString();

}else{

document.cookie = _name+"="+encodeURIComponent(_value)+"; path=/;";

}

}

// 读取cookie(查)

/*

查 getCookie("a")

*/

function getCookie(_name){

var str = document.cookie; // "a=1; b=2; c=3"

var arr = str.split("; "); // 一定要注意多一个空格

var l = arr.length;

for( var i=0; i

你可能感兴趣的:(cookie)