获得cookie方法:
function GetCookie(sName) {
var aCookie = document.cookie.split("; ");
alert(aCookie);
for (var i = 0; i < aCookie.length; i++) {
var aCrumb = aCookie[i].split("=");
if (sName == aCrumb[0])
return unescape(aCrumb[1]);
}
return null;
} 调用js方法 : var hadValidCode = GetCookie("ValidateCodes");
是ValidateCode.aspx.cs页面写的,在登录页载入ValidateCode.aspx.cs和cookie方法 :Response.Cookies.Add(new HttpCookie("ValidateCodes", code));
但是获得的cookie值一直是空的
function GetCookie(sName) {
var aCookie = document.cookie.split("; ");
alert(aCookie);
for (var i = 0; i < aCookie.length; i++) {
var aCrumb = aCookie[i].split("=");
if (sName == aCrumb[0])
return unescape(aCrumb[1]);
}
return null;
} 调用js方法 : var hadValidCode = GetCookie("ValidateCodes");
是ValidateCode.aspx.cs页面写的,在登录页载入ValidateCode.aspx.cs和cookie方法 :Response.Cookies.Add(new HttpCookie("ValidateCodes", code));
但是获得的cookie值一直是空的
你这是在后台写的?后台能直接这样调用页面的JS?
function cookie(key, value, options) {
// key and value given, set cookie...
if (arguments.length > 1 && (value === null || typeof value !== "object")) {
options = jQuery.extend({}, options); if (value === null) {
options.expires = -1;
} if (typeof options.expires === 'number') {
var days = options.expires, t = options.expires = new Date();
t.setDate(t.getDate() + days);
} return (document.cookie = [
encodeURIComponent(key), '=',
options.raw ? String(value) : encodeURIComponent(String(value)),
options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
options.path ? '; path=' + options.path : '',
options.domain ? '; domain=' + options.domain : '',
options.secure ? '; secure' : ''
].join(''));
} // key and possibly options given, get cookie...
options = value || {};
var result, decode = options.raw ? function (s) { return s; } : decodeURIComponent;
return (result = new RegExp('(?:^|; )' + encodeURIComponent(key) + '=([^;]*)').exec(document.cookie)) ? decode(result[1]) : null;
};存储:cookie(cookie的名字, cookie的值, { expires: 7 });
调用:var cookie_value = cookie(cookie的名字);
希望可以帮到你哦!!!