网址编码

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>

效果:


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值