decodeURI()定义和用法:decodeURI() 函数可对 encodeURI() 函数编码过的URI 进行解码。
语法:decodeURI(URIstring)
参数 描述:URIstring 必需。一个字符串,含有要解码的 URI 或其他要解码的文本。
返回值:URIstring 的副本,其中的十六进制转义序列将被它们表示的字符替换。
decodeURIComponent()定义和用法:decodeURIComponent() 函数可对 encodeURIComponent() 函数编码的 URI 进行解码。
语法:decodeURIComponent(URIstring)
参数 描述:URIstring 必需。一个字符串,含有编码 URI 组件或其他要解码的文本。
返回值:URIstring 的副本,其中的十六进制转义序列将被它们表示的字符替换。
<html> <body> <script type="text/javascript"> var test1="http://www.wljcz.com/My first/"; var nn=encodeURI(test1); var now=decodeURI(test1); document.write(nn+ "<br />"); document.write(now); var test1="http://www.wljcz.com/My first/"; var bb=encodeURIComponent(test1); var nnow=decodeURIComponent(bb); document.write(bb+ "<br />"); document.write(nnow); </script> </body> </html>
关于window.location.href跳转到其他页面中文编码问题
此href直接连接其他页面,一端用JavaScript加密另一端用JavaScript解密
1)加密端
encodeURI(encodeURI(String)); //String为要加密的字符串
2)解密端
decodeURI(String); //String为要解密的字符串