function get_Cookie(cookieName) { var cookieString = document.cookie; var start = cookieString.indexOf(cookieName + '='); if (start == -1) return null; start += cookieName.length + 1; var end = cookieString.indexOf(';', start); if (end == -1) return unescape(cookieString.substring(start)); return unescape(cookieString.substring(start, end)); }
|
[ 原文地址 ]
http://blog.chinaunix.net/u1/53398/showart.php?id=491333
另一种简便的写法:
function getCookie(name){
var a = document.cookie.match(new RegExp("(^|;)"+name+"=([^;]*)"));
return a?a[2]:a;
}
注意与下面写法的差异,这种写法对于cookie abc 和bc 同时出现时会有问题的:
function getCookie(name){
var a=document.cookie.match(new RegExp(name+"=([^;]*)"));
return a?a[1]:a;
}