用javascript对URL进行编码时有3个函数可选:escape,encodeURI,encodeURIComponent函数.下面介绍一下它们的用法和区别。
1、 传递参数时需要使用encodeURIComponent,这样组合的url才不会被#等特殊字符截断。
例如:
<script language="javascript">document.write(''<a href="http://www.phpzixue.cn/?logout&aid=7&u=''+encodeURIComponent("http://www.phpzixue.cn/")+''">退出</a>'');</script>
2、 进行url跳转时可以整体使用encodeURI
例如: Location.href=encodeURI(http://cang.baidu.com/do/s?word=中国asp之家&ct=21);
3、...