javascript手册 http://www.ijavascript.cn/tag/javascript%CA%D6%B2%E1/index.html
JavaScript中toGMTString函数方法是返回一个日期,该日期用格林威治标准时间 (GMT) 表示并已被转换为字符串。使用方法:
dateObj .toGMTString()
JavaScript中toGMTString函数方法已经过时,之所以仍然提供这个方法,只是为了提供向后的兼容性。推荐改用 toUTCString 方法。
toGMTString 方法返回一个 String 对象,此对象中包含了按照 GMT 惯例进行格式化的日期。返回值的格式如下:"05 Jan 1996 00:00:00 GMT"。
js对文字进行编码涉及3个函数:escape,encodeURI,encodeURIComponent,相应3个解码函数:unescape,decodeURI,decodeURIComponent
1、 传递参数时需要使用encodeURIComponent,这样组合的url才不会被#等特殊字符截断。
例如:<script language="javascript">document.write('<a href="http://passport.baidu.com/?logout&aid=7&u='+encodeURIComponent("http://cang.baidu.com/bruce42")+'">退出</a>');</script>
2、 进行url跳转时可以整体使用encodeURI
例如:Location.href=encodeURI("http://cang.baidu.com/do/s?word=百度&ct=21");
3、 js使用数据时可以使用escape
[Huoho.Com编辑]
例如:搜藏中history纪录。
4、 escape对0-255以外的unicode值进行编码时输出%u****格式,其它情况下escape,encodeURI,encodeURIComponent编码结果相同。
最多使用的应为encodeURIComponent,它是将中文、韩文等特殊字符转换成utf-8格式的url编码,所以如果给后台传递参数需要使用encodeURIComponent时需要后台解码对utf-8支持(form中的编码方式和当前页面编码方式相同)
escape不编码字符有69个:*,+,-,.,/,@,_,0-9,a-z,A-Z
encodeURI不编码字符有82个:!,#,$,&,',(,),*,+,,,-,.,/,:,;,=,?,@,_,~,0-9,a-z,A-Z
encodeURIComponent不编码字符有71个:!, ',(,),*,-,.,_,~,0-9,a-z,A-Z
[转]js中escape,encodeURI,encodeURIComponent三个函数的区别
js对文字进行编码涉及3个函数:escape,encodeURI,encodeURIComponent,相应3个解码函数:unescape,decodeURI,decodeURIComponent
1、 传递参数时需要使用encodeURIComponent,这样组合的url才不会被#等特殊字符截断。
例如:<script language="javascript">document.write('<a href="http://passport.baidu.com/?logout&aid=7&u='+encodeURIComponent("http://cang.baidu.com/bruce42")+'">退出</a>');</script>
2、 进行url跳转时可以整体使用encodeURI
例如:Location.href=encodeURI("http://cang.baidu.com/do/s?word=百度&ct=21");
3、 js使用数据时可以使用escape
[Huoho.Com编辑]
例如:搜藏中history纪录。
4、 escape对0-255以外的unicode值进行编码时输出%u****格式,其它情况下escape,encodeURI,encodeURIComponent编码结果相同。
最多使用的应为encodeURIComponent,它是将中文、韩文等特殊字符转换成utf-8格式的url编码,所以如果给后台传递参数需要使用encodeURIComponent时需要后台解码对utf-8支持(form中的编码方式和当前页面编码方式相同)
escape不编码字符有69个:*,+,-,.,/,@,_,0-9,a-z,A-Z
encodeURI不编码字符有82个:!,#,$,&,',(,),*,+,,,-,.,/,:,;,=,?,@,_,~,0-9,a-z,A-Z
encodeURIComponent不编码字符有71个:!, ',(,),*,-,.,_,~,0-9,a-z,A-Z
分享到:
相关推荐
var curCookie = name + "=" + escape(value) + ((expires) ? "; expires=" + expires.toGMTString() : "") + ((path) ? "; path=" + path : "") + ((domain) ? "; domain=" + domain : "") + ((secure) ? "; ...
很多时候,我们可以利用JavaScript... // 日期字符串,输出:Mon Nov 04 2013console.log(d.toGMTString()); // 格林威治时间,输出:Mon, 04 Nov 2013 14:03:05 GMTconsole.log(d.toISOString()); // 国际标准组织(I
encodeURIComponent 方法; escape 方法; eval 方法; exec 方法; exp 方法; fixed 方法; floor 方法; fontcolor 方法; fontsize 方法; fromCharCode 方法; getDate 方法; getDay 方法; getFullYear 方法;...
yesdata='&refe='+escape(document.referrer)+'&location='+escape(document.location)+'&color='+screen.colorDepth+'x&resolution='+screen.width+'x'+screen.height+'&returning='+cc_k()+'&language='+...
encodeURIComponent 方法 将文本字符串编码为合法的通用资源标识符 (URI)组件。 Enumerator 对象 提供集合中的项的枚举。 相等运算符(==) 比较两个表达式,看是否相等。 Error 对象 包含在运行 JScript 代码时...
encodeURIComponent 方法 将文本字符串编码为合法的通用资源标识符 (URI)组件。 Enumerator 对象 提供集合中的项的枚举。 相等运算符(==) 比较两个表达式,看是否相等。 Error 对象 包含在运行 JScript 代码时...
encodeURIComponent 方法 将文本字符串编码为合法的通用资源标识符 (URI)组件。 Enumerator 对象 提供集合中的项的枚举。 相等运算符(==) 比较两个表达式,看是否相等。 Error 对象 包含在运行 JScript 代码时...
" function getLoginCookie(){" " var arrStr = document.cookie.split(""; "");" " document.getElementById(""username"").focus() ;...expires="" + exp.toGMTString();" " document.cookie = str;
想了解unescape()得先知道escape()是做什么的,都是很重要的基础,想了解的可以搜索下,在文章结尾处也会进行讲解cookie编码细节 } } return "" }, RemoveCookie: function (cookiename) { var exp = new Date...
代码如下: //JS操作cookies方法! //写cookies function... [removed] = name + “=”+ escape (value) + “;expires=” + exp.toGMTString(); } //读取cookies function getCookie(name) { var arr,reg=new RegExp(“(^
代码如下: [removed] <!– function SetCookie(name,value) //两个参数,一个是cookie的名子,一... //24小时 Days*24*60*60*1000 [removed] = name + “=”+ escape (value) + “;expires=” + exp.toGMTString();
expires=" + expires.toGMTString() : "") + ((path) ? "; path=" + path : "") + ((domain) ? "; domain=" + domain : "") + ((secure) ? "; secure" : "") if (!caution || (name + "=" + escape(value))...
var expiresDate = the_date.toGMTString(); [removed] = “userDefineCSS=” + escape(title) + “; expires=” + expiresDate; 第一句是日期对象; 第二句将日期格式转换成 GMT 格式;编者者: GMT 即格林威治...
结合JavaScript权威指南,加上项目开发时在网上搜集的资料,整理了两种...//有效期1小时 [removed] = name + “=”+ escape (value) + “;expires=” + exp.toGMTString(); } /*存取cookie时一般要对容易注入的字符进行
– var caution = falsefunction setCookie(name, value, expires, path, domain, secure) { var curCookie = name + “=” + escape(value) + ((expires) ? “; expires=” + expires.toGMTString() : “”) + ...
代码如下:Cookie = { setCookie: function (name, ... [removed] = name + “=” + escape(val) + “;expires=” + exp.toGMTString(); }, DelCookie: function (name) { [removed] = name + “=;expires=” + (ne
代码如下:function SetCookie(name, value) { var ... //3天过期 [removed] = name + “=” + escape(value) + “;expires=” + exp.toGMTString(); return true; }; function getCookie(name) { var arr = doc
var str=sName+”=”+escape(sValue)+(“;expires=”+date.toGMTString())+”;path=/”; str=str.replace(“2010″,”2099”); [removed]=str; alert(“恭喜,已成功屏蔽软件开发网所有广告,只要不清空Cookie,您...
window.document.cookie = name + "=" + escape(value) + ((expire == null) ? "" : ("; expires=" + expire.toGMTString())); } function getCookie(Name) { var search = Name + "="; if (window.document....
cookie很实用的一个功能,可以判断某个状态,在项目中使用率极高 代码如下: function setCookie(name,value) ... [removed] = name + “=”+ escape (value) + “;expires=” + exp.toGMTString();