我写的,可以读子键// getCookie("bbs","username") getCookie("bbs") 获取cookie,可选子键
function getCookie(mainKey,subKey) {
var reg = new RegExp("(^| )"+mainKey+"=([^;]*)(;|$)");
var arr = document.cookie.match(reg);
if (arguments.length == 2) {
if (arr!=null)
return key(subKey,arr[2]);
else
return null;
} else if (arguments.length == 1) {
if (arr!=null)
return unescape(arr[2]);
else
return null;
} function key(subKey,findWith) {
var arr,reg = new RegExp("(^| |&)"+subKey+"=([^&]*)(&|$)");
var findWith = findWith?findWith:document.cookie;
if (arr =  findWith.match(reg))
return unescape(arr[2]);
else
return null;
}
}