語法
js
get(name)
引數
name-
要返回的引數名稱。
返回值
如果找到給定的搜尋引數,則返回一個字串;否則返回 null。
示例
如果你的頁面的 URL 是 https://example.com/?name=Jonathan&age=18,你可以使用以下方法解析出 'name' 和 'age' 引數:
js
let params = new URLSearchParams(document.location.search);
let name = params.get("name"); // is the string "Jonathan"
let age = parseInt(params.get("age"), 10); // is the number 18
請求查詢字串中不存在的引數將返回 null
js
let address = params.get("address"); // null
規範
| 規範 |
|---|
| URL # dom-urlsearchparams-get |
瀏覽器相容性
載入中…