// 简单获取
cookie .getcookie("key1");
cookie .getcookie("key2");
cookie .getcookie("key3");
cookie .getcookie("key4");
// 获取key4的子键k1值
cookie .getchild("key4","k1");
cookie .expire("key1");
cookie .expire("key2");
cookie .expire("key3");
cookie .expire("key4");
var cookie = new jscookie();
// 普通设置
cookie .setcookie("key1","val1");
// 过期时间为一年
var expire_time = new date();
expire_time.setfullyear(expire_time.getfullyear() + 1);
cookie .setcookie("key2","val2",expire_time);
// 设置域及路径,带过期时间
cookie .setcookie("key3","val3",expire_time,".cnblogs.com","/");
// 设置带子键的cookie,子键分别是k1,k2,k3
cookie .setcookie("key4","k1=1&k2=2&k3=3");
利用正则来处理cookie
/**************************************************
参数说明:
smainname cookie名
ssubname cookie子键名,留空表示单值cookie
**************************************************/
function getcookie(smainname, ssubname)
{
var re = new regexp((ssubname ? smainname + "=(?:.*?&)*?" + ssubname + "=([^&;$]*)" : smainname + "=([^;$]*)"),"i");
return re.test(unescape(document.cookie)) ? regexp["$1"] : "";
}