<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
<meta charset="utf-8" />
</head>
<body>
<script type="text/javascript">
var url = 'http://localhost:53756/url编码.html';
var result = window.encodeURI(url);//encodeURI()方法只是将需要编码的部分进行编码
alert(result);//输出http://localhost:53756/url%E7%BC%96%E7%A0%81.html
var result2 = window.encodeURIComponent(url);//encodeURIComponent()方法是将整个url都进行编码,这样编码后在服务器是识别不出来的,所以使用时只对需要编码的部分进行编码
alert(result2);//输出http%3A%2F%2Flocalhost%3A53756%2Furl%E7%BC%96%E7%A0%81.html
</script>
</body>
</html>