Skip to content
New issue

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

JavaScript:URLSearchParams 解析地址栏参数 #32

Open
smileyby opened this issue May 25, 2021 · 0 comments
Open

JavaScript:URLSearchParams 解析地址栏参数 #32

smileyby opened this issue May 25, 2021 · 0 comments
Labels

Comments

@smileyby
Copy link
Owner

let query = window.location.search.slice(1);
let query = 'ie=utf-8&f=8&rsv_bp=1&tn=baidu&ie=wtf';

需要注意 query 是地址中 ? 之后的部分 window.location.search.slice(1)
let searchParams = new URLSearchParams(query);
for (let keyValue of searchParams) {
console.log(keyValue);
}
console.log('1',searchParams.getAll('ie')); // ["utf-8", "wtf"]
console.log('2',searchParams.get('tn')); // "baidu"
console.log('3',searchParams.getAll('tn')); // ["baidu"]

@smileyby smileyby added the JavaScript ☀️ JavaScript label May 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant