为了解析 URL 字符串,现代浏览器提供了一个名为的类URLSearchParams,这是提取 URL 值的最简单方法。您可以通过传递该类的search属性window.location(在删除初始“?”之后)创建该类的实例,然后它将为您完成所有工作:// eg. https://example.com/?name=Jonathan&age=18&i=aGVsbG8gd29ybGQ=const params = new URLSearchParams(window.location.search.substring(1)); // remove "?"const name = params.get("name"); // is the string "Jonathan"const age = parseFloat(params.get("age")); // is the number 18const i = whateverDecodingFunctionYouUse(params.get("i")); // decoded aGVsbG8gd29ybGQ请参阅:https ://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams/