--- title: URLSearchParams.set() slug: Web/API/URLSearchParams/set translation_of: Web/API/URLSearchParams/set ---
{{ApiRef("URL API")}}{{SeeCompatTable}}
{{domxref("URLSearchParams")}}接口的set()方法用于设置和搜索参数相关联的值。如果设置前已经存在匹配的值,该方法会删除多余的,如果将要设置的值不存在,则创建它
URLSearchParams.set(name, value)
Void
let url = new URL('https://example.com?foo=1&bar=2'); let params = new URLSearchParams(url.search.slice(1)); //Add a third parameter. params.set('baz', 3);
Specification | Status | Comment |
---|---|---|
{{SpecName('URL', '#dom-urlsearchparams-set', "set()")}} | {{Spec2('URL')}} | Initial definition. |
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari (WebKit) |
---|---|---|---|---|---|
Basic support | {{CompatChrome(49.0)}} | {{CompatVersionUnknown}} | {{CompatNo}} | {{CompatVersionUnknown}} | {{CompatUnknown}} |
Feature | Android | Android Webview | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile | Chrome for Android |
---|---|---|---|---|---|---|---|
Basic support | {{CompatNo}} | {{CompatChrome(49.0)}} | {{CompatVersionUnknown}} | {{CompatNo}} | {{CompatVersionUnknown}} | {{CompatUnknown}} | {{CompatChrome(49.0)}} |