这篇翻译不完整。请帮忙从英语翻译这篇文章

URL 接口的searchParams属性返回一个URLSearchParams对象,从这个对象中能获取到URL中的GET参数。

searchParams用于访问url中的查询参数。比如http://localhost?a=1&b=2,searchParams等于{a: 1, b: 2}。

语法

var urlSearchParams = URL.searchParams;

值类型

URLSearchParams 对象

例子

如果你的url是 https://example.com/?name=Jonathan&age=18 ,你可以这样解析url,然后得到name和age的值。

let params = (new URL(document.location)).searchParams;
let name = params.get("name"); // "Jonathan"
let age = parseInt(params.get("age")); // 18

Specifications

Specification Status Comment
URL
searchParams
Living Standard Initial definition.

Browser compatibility

We're converting our compatibility data into a machine-readable JSON format. This compatibility table still uses the old format, because we haven't yet converted the data it contains. Find out how you can help!

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support 51.0 52.0 (52.0) ? ? ?
Feature Android Android Webview Firefox Mobile (Gecko) Firefox OS IE Mobile Opera Mobile Safari Mobile Chrome for Android
Basic support 51.0 51.0 52.0 (52.0) ? ? ? ? 51.0

文档标签和贡献者

 此页面的贡献者: lujing2, theanarkh
 最后编辑者: lujing2,