// 示例代码:使用 JavaScript 解码 URL 编码的字符串
// 假设我们有一个经过 URL 编码的字符串
let encodedURL = "https%3A%2F%2Fwww.example.com%2Fpath%3Fquery%3Dvalue%26another%3D123";
// 使用 decodeURIComponent() 函数解码 URL 编码的字符串
let decodedURL = decodeURIComponent(encodedURL);
console.log(decodedURL); // 输出: https://www.example.com/path?query=value&another=123
// 如果要解码整个 URL(包括特殊字符),可以使用 decodeURI()
let encodedFullURL = "https%3A%2F%2Fwww.example.com%2Fpath%3Fquery%3Dvalue%26another%3D123";
let decodedFullURL = decodeURI(encodedFullURL);
console.log(decodedFullURL); // 输出: https://www.example.com/path?query=value&another=123
// 注意:decodeURIComponent 适用于解码 URL 的组件(如查询参数),而 decodeURI 适用于解码完整的 URL。
encodeURIComponent()
和 encodeURI()
是用于对 URL 进行编码的函数,而 decodeURIComponent()
和 decodeURI()
则是用于解码 URL 的函数。decodeURIComponent()
用于解码 URL 中的单个组件(例如查询参数),而 decodeURI()
用于解码整个 URL。encodedURL
是一个经过 URL 编码的字符串,通过 decodeURIComponent()
可以将其转换为原始的、可读的 URL 形式。上一篇:js 获取url ?后面的参数
下一篇:js 获取url地址
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站