// 示例代码:使用 JavaScript 进行 URL 编码和解码
// 使用 encodeURIComponent 对字符串进行编码
let originalString = "https://example.com/path?name=John Doe&city=New York";
let encodedString = encodeURIComponent(originalString);
console.log("Encoded String:", encodedString);
// 使用 decodeURIComponent 对编码后的字符串进行解码
let decodedString = decodeURIComponent(encodedString);
console.log("Decoded String:", decodedString);
// 解释说明:
// 1. encodeURIComponent: 对整个 URI 或 URI 组件进行编码,适用于编码查询参数、片段标识符等。
// 2. decodeURIComponent: 对 encodeURIComponent 编码的字符串进行解码,恢复为原始字符串。
// 注意:encodeURIComponent 不会对某些特殊字符(如 '/')进行编码,如果需要对完整的 URL 进行编码,可以考虑使用 encodeURI。
上一篇:js unicode编码转换中文
下一篇:js unicode转码
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站