一、基本概念
encodeURI和decodeURI是成对来使用的,因为浏览器的`地址栏有中文字符的话,可以会出现不可预期的错误,所以可以encodeURI把非英文字符转化为英文编码,decodeURI可以用来把字符还原回来。encodeURI方法不会对下列字符进行编码:":"、"/"、";" 和 "?",encodeURIComponent方法可以对这些字符进行编码。
decodeURI()方法相当于de(URIString, "UTF-8");
encodeURI()方法相当于de(URIString, "UTF-8");
二、例子
复制代码 代码如下:
var uriStr = "张三&num=001 zs";
var uriec = encodeURI(uriStr);
e("编码后的" + uriec);
var uridc = decodeURI(uriec);
e("解码后的" + uridc);
编码后的
解码后的张三&num=001 zs