escape() 方法:
encodeURI() 方法:
encodeURIComponent() 方法:
另外,encodeURI/encodeURIComponent是在javascript1.5之后引进的,escape则在javascript1.0版本就有。
<title> url字符串的加密与解密 </title>
<script language="JavaScript">
var str="http://hi.baidu.com/bbjjss2008l?country=中国&name=jz";
var urlStr=escape(str);
document.write("escape方法加密:<br>"+urlStr+"<br>解密后url字符串是:<br>"+unescape(str));
urlStr=encodeURI(str);
document.write("<br>encodeURI:方法加密:<br>"+urlStr+"<br>解密后url字符串是:<br>"+decodeURI(str));
urlStr=encodeURIComponent(str);
document.write("<br>encodeURIComponent:方法加密:<br>"+urlStr+"<br>解密后url字符串是:<br>"+decodeURIComponent(str));
</script>
本文介绍了JavaScript中用于URL编码的三种方法:escape()、encodeURI() 和 encodeURIComponent()。详细解释了每种方法的适用场景及不被编码的字符,并通过实例展示了如何使用这些方法对URL进行编码。
1483

被折叠的 条评论
为什么被折叠?



