encodeURLComponent()函数可以把字符串作为URL组件进行编码
decodeURLComponent()函数可以把字符串作为URl组件进行解码
由于后台对于传输过去的网址中的特殊的符号,他们并不认识,所以需要解码成,后台能够认识和识别的符号,比如符号?// 都需要进行转义。
<!DOCTYPE html>
<html><head lang="en">
<meta charset="UTF-8">
<title></title>
</head>
<body>
</body>
</html>
<script>
var url = "http://www.itcast.cn?name=andy";
console.log(encodeURIComponent(url)); // 编码
var afterUrl = encodeURIComponent(url);
console.log(decodeURIComponent(afterUrl)); // 解码
//解码url使得后台识别
var afterUrl=encodeURLComponent(url);
console.log(decodeURIComonent)
</script>
效果: