JavaScript encodeURIComponent()
示例
编码 URI
let uri = "https://w3schools.com/my test.asp?name=ståle&car=saab";
let encoded = encodeURIComponent(uri);
自己动手试一试 »
描述
encodeURIComponent()
方法编码 URI 组件。
encodeURIComponent()
方法编码特殊字符,包括: , / ? : @ & = + $ #
语法
encodeURIComponent(uri)
参数
参数 | 描述 |
uri | 必需。 要编码的 URI。 |
返回值
类型 | 描述 |
一个字符串 | 编码后的 URI。 |
浏览器支持
encodeURIComponent()
是 ECMAScript1 (ES1) 功能。
ES1 (JavaScript 1997) 在所有浏览器中都得到完全支持
Chrome | Edge | Firefox | Safari | Opera | IE |
是 | 是 | 是 | 是 | 是 | 是 |