decodeURIComponent() URL 解码
最后更新:2026-09-09
decodeURIComponent() URL 解码
decodeURIComponent 解码由 encodeURIComponent 编码的字符串。读取 URL 查询参数的标准方法。
| 分类 | 全局函数 |
|---|---|
| ES 版本 | ES1 |
📝 语法
decodeURIComponent(编码字符串);
⚙️ 参数
| encoded | 要解码的字符串。 |
|---|
返回值:解码后的字符串。
是否修改原值:否(返回新值)
▶ 示例
编辑下方代码,点击运行,在输出面板查看结果:
运行结果:
搜索 JavaScript
💡 提示 读取 URL 参数用 URLSearchParams(自动解码)——不需要手动 decodeURIComponent。
⚠️ 警告 解码非法编码的字符串会抛 URIError——用 try/catch 包裹。
🌐 浏览器支持
| 浏览器 | |||||
|---|---|---|---|---|---|
| decodeURIComponent() | ✓ v1 | ✓ v12 | ✓ v1 | ✓ v1 | ✓ v1 |
| 所有现代浏览器均支持 | |||||
🏷️ 相关条目
💡 相关案例
更多实战案例即将上线,敬请期待。
📚 相关教程
❓ 常见问题
QdecodeURIComponent 和 decodeURI 的区别?
AdecodeURIComponent 解码所有字符;decodeURI 保留 URL 结构字符。
Q解码失败会怎样?
A抛 URIError——用 try/catch 捕获。
QURLSearchParams 能替代手动解码吗?
A能——自动解码且提供便捷的 get/getAll 方法。