我写的,可以读子键// 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;
}
}
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;
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货