Laravel  
laravel
文档
数据库
架构
入门
php技术
    
Laravelphp
laravel / php / java / vue / mysql / linux / python / javascript / html / css / c++ / c#

js url decode

作者:让固执流亡丶   发布日期:2025-10-08   浏览:46

// 示例代码:使用 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地址

大家都在看

js 数组对象排序

js 数组删掉第一个值

js fill

js 数组连接

js json数组

js 数组复制

js 复制数组

js 数组拷贝

js 对象数组合并

js 对象转数组

Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3

Laravel 中文站