URLSearchParams:toString() 方法
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
备注: 此特性在 Web Worker 中可用。
URLSearchParams
接口的 toString()
方法返回适用于 URL 中的查询字符串。
备注:
方法返回不带问号的查询字符串。这与 Location.search
、HTMLAnchorElement.search
和 URL.search
都不同,它们均带有问号。
语法
js
toString()
参数
无。
返回值
一个不带问号的字符串(如果未设置查询参数,则返回空字符串)。
示例
js
const url = new URL("https://example.com?foo=1&bar=2");
const params = new URLSearchParams(url.search);
// 添加第二个参数。
params.append("foo", 4);
console.log(params.toString()); // 输出“foo=1&bar=2&foo=4”
规范
Specification |
---|
URL # urlsearchparams-stringification-behavior |
浏览器兼容性
Report problems with this compatibility data on GitHubdesktop | mobile | server | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
toString |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.