URLSearchParams.toString()
URLSearchParams
接口的 toString()
方法返回适用在 URL 中的查询字符串。
语法
URLSearchParams.toString()
返回值
字符串
实例
let url = new URL('https://example.com?foo=1&bar=2');
let params = new URLSearchParams(url.search.slice(1));
//Add a second foo parameter.
params.append('foo', 4);
console.log(params.toString());
//Prints 'foo=1&bar=2&foo=4'.
规范
Specification |
---|
URL Standard # urlsearchparams-stringification-behavior |
浏览器兼容
BCD tables only load in the browser
参考
- Other URL-related interfaces:
URL
,URLUtils
. - Google Developers: Easy URL manipulation with URLSearchParams