We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
获取 http://www.example.com/page/index.html?name=hello&key=world#view-show-name
// 获取URL信息 location /* { "href": "http://www.example.com/page/index.html?name=hello&key=world#view-show-name", "ancestorOrigins": {}, "origin": "http://www.example.com", "protocol": "http:", "host": "www.example.com", "hostname": "www.example.com", "port": "", "pathname": "/page/index.html", "search": "?name=hello&key=world", "hash": "#view-show-name" } */
兼容大部分浏览器
function getURLParam ( name ) { if (typeof name === 'undefined') { return null; } let paramReg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i"); let value = window.location.search.substr(1).match(paramReg); if (value != null) { return unescape(value[2]); } return false; } getURLParam('name') // 返回 'hello' getURLParam('key') // 返回 'world'
只兼容新版浏览器
let params = new URLSearchParams(location.search); params.has('name'); // 返回 true params.get('name'); // 返回 'hello' params.getAll("name"); // 返回 ['hello']
The text was updated successfully, but these errors were encountered:
No branches or pull requests
URL信息
获取 http://www.example.com/page/index.html?name=hello&key=world#view-show-name
获取URL信息
获取URL参数
一般方法
兼容大部分浏览器
高阶方法
只兼容新版浏览器
The text was updated successfully, but these errors were encountered: