toString()
方法在
URLSearchParams
interface returns a query string suitable for use in a URL.
注意 : This method returns the query string without the question mark. This is different from window.location.search , which includes it.
URLSearchParams.toString()
None.
A
DOMString
, without the question mark. (Returns an empty string if no search parameters have been set.)
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'
// note: params can also be directly created
let url = new URL('https://example.com?foo=1&bar=2');
let params = url.searchParams;
// or even simpler
let params = new URLSearchParams('foo=1&bar=2');
| 规范 | 状态 | 注释 |
|---|---|---|
|
URL
The definition of 'toString() (see "stringifier")' in that specification. |
实时标准 | 初始定义。 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
toString
|
Chrome 49 | Edge 17 | Firefox 29 | IE 不支持 No | Opera 36 | Safari Yes | WebView Android 49 | Chrome Android 49 | Firefox Android 29 | Opera Android 36 | Safari iOS Yes | Samsung Internet Android 5.0 |
完整支持
不支持
URLSearchParams