1.首先写一个假的地址(q=URLUtils.searchParams&topic=api
)相当于当前的window.location.href
1 2 3 4 5 6 7 8 9 10 11 |
const urlParams = new URL(window.location.href); urlParams.searchParams.has("topic") === true; // true urlParams.searchParams.get("topic") === "api"; // true urlParams.searchParams.getAll("topic"); // ["api"] urlParams.searchParams.get("foo") === ""; // true urlParams.searchParams.append("topic", "webdev"); urlParams.searchParams.toString(); // "q=URLUtils.searchParams&topic=api&topic=webdev" urlParams.searchParams.set("topic", "More webdev"); urlParams.searchParams.toString(); // "q=URLUtils.searchParams&topic=More+webdev" urlParams.searchParams.delete("topic"); urlParams.searchParams.toString(); // "q=URLUtils.searchParams" |