网站制作学习网JS脚本→正文:javascript加密解密url
字体:

javascript加密解密url

JS脚本 2010/2/24 10:00:02  点击:不统计

转www.载for网站制作学习asp必.cn究
encodeURI()和encodeURIComponent()方法是将编码传递给浏览器的URI(统一资源标识).有效的URI不包括某些字符,如空格,#,$等.这两个函数将那些特殊字符替换仅为utf-8的编码,让浏览器接收它们.而decodeURI()和decodeURIComponent()是对编码后的解码.

encodeURI()和encodeURIComponent()的区别是:前一个是不会将字符串中出现的特殊字符编码,如:冒号,前斜杠,问号,英镑符号.而后面的encodeURIComponent()则对字符串中所有的非标准字符进行编码
举例说明:
var str ="http://www.forasp.cn/tool/color 123.htm";
var str1 = encodeURI(str);
var str2 = encodeURIComponent(str);
结果
str1 http://www.forasp.cn/tool/color%20123.htm
str2 http%3A%2F%2Fwww.forasp.cn%2Ftool%2Fcolor%20123.htm

而decodeURI()和decodeURIComponent()是对编码后的解码.也就是对上面加密的解密,真好相反
举例
str3 = decodeURI(str1);
str4 = decodeURIComponent(str2);
解密出来就是 str http://www.forasp.cn/tool/color 123.htm

www.forasp.cn原创,转载请注明

网f站o学a习s制p作.cn

·上一篇:javascript时间函数 >>    ·下一篇:javascript数学计算Math() >>
推荐文章
最新文章