asp.net 后台代码
Response.Cookies.Add(new HttpCookie("showUsername", System.Web.HttpUtility.UrlEncode(showUsername, Encoding.UTF8)));
前台js
function getCookie(Name) //cookies读取
{
var search = Name + "="
if (document.cookie.length > 0) {
offset = document.cookie.indexOf(search)
if (offset != -1) {
offset += search.length
end = document.cookie.indexOf(";", offset)
if (end == -1) end = document.cookie.length
return decodeURIComponent(document.cookie.substring(offset, end))
}
else return ""
}
return ""
}
取值:getCookie("showUsername")