javascript——URI的编解码方法

     有效的URI(统一资源标示符)是不能包含某些字符的,如空格,所以需要进行编码,编码方法有:encodeURI()和encodeURIComponent(),

    对编的码进行解码方法有:decodeURI()和decodeURIComponent()。

    encodeURI()编的码只能decodeURI()解

    encodeURIComponent()编的码只能decodeURIComponent()解,

    encodeURI():用于编码完整的URI,它不对URI中的特殊字符进行编码:例如冒号、前斜杠、问号、英镑符号     

var str0=encodeURI("http://www.cnblogs.com/ 2012/ 71.html");
//结果:http://www.cnblogs.com/%202012/%2071.html     
      只对空格进行了编码

    encodeURIComponent():用于编码URI的某一部分,它对URI中的所有非标准字符进行编码

var str1=encodeURIComponent("http://www.cnblogs.com/ 2012/ 71.html");
//结果:http%3A%2F%2Fwww.cnblogs.com%2F%202012%2F%2071.html
原文地址:https://www.cnblogs.com/wolfocme110/p/4290521.html