url编码

本文深入探讨了URL编码的两种主要方法:encodeURI()和encodeURIComponent()。通过实例对比,展示了这两种方法在处理URL中特殊字符时的不同之处,encodeURI()仅编码需要的部分,而encodeURIComponent()则对整个URL进行编码。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<!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>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值