Javascript中有decodeURI和encodeURI两个函数

.net端

C# code
    
    
    
    
private void setCookie( string name, string value) { System.Web.HttpCookie cookie = new HttpCookie(name, System.Web.HttpUtility.UrlEncode(value)); cookie.Expires = System.DateTime.Now.AddDays( 30 ); cookie.Path = " / " ; System.Web.HttpContext.Current.Response.AppendCookie(cookie); } private string getCookie( string name) { if (Request.Cookies[name] != null ) { return System.Web.HttpUtility.UrlDecode(Request.Cookies[name].Value); } else { return "" ; } }




Javascript端

JScript code
    
    
    
    
function setCookie(name,value) { var Days = 30 ; var expTime = new Date(); expTime.setTime(expTime.getTime() + Days * 24 * 60 * 60 * 1000 ); document.cookie = name + " = " + encodeURI(value) + " ;expires= " + expTime.toGMTString() + " ;path=/ " ; } function getCookie(name) { var arrCookies = document.cookie.match( new RegExp( " (^| ) " + name + " =([^;]*)(;|$) " )); if (arrCookies != null ) return decodeURI(arrCookies[ 2 ]); return null ; }

你可能感兴趣的:(Javascript中有decodeURI和encodeURI两个函数)