javascript 获取查询字符串
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14463771/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
javascript get querystring
提问by user1898657
Possible Duplicate:
obtaining querystring from current url in javascript?
I was to get everything after the question mark in the url. Ive seen a way to do it that does not require a function but cannot find it for the life of me.
我要在网址中的问号之后获取所有内容。我见过一种不需要函数但在我的生活中找不到它的方法。
url
网址
fsdhfbsdfj/index.html?hello
get
得到
hello
回答by Denys Séguret
Use
用
var query = window.location.search;
If you want to get rid of the starting "?", use
如果要去掉开头的“?”,请使用
var query = window.location.search.slice(1);
回答by kennebec
var querystring=window.location.search.substring(1);
回答by Christophe
Your title says "get querystring", but your question says "get everything after the question mark" which is something different and can include both a querystring and a hash.
您的标题说“获取查询字符串”,但您的问题说“获取问号后的所有内容”,这是不同的,可以同时包含查询字符串和哈希值。
I assume that when you say "the" url you are talking about the current Web page.
我假设当您说“the” url 时,您是在谈论当前的网页。
To get the querystring:
获取查询字符串:
window.location.search
To get everything after the first ?:
在第一个之后获得一切?:
window.location.href.split("?").slice(1).join("?");
回答by Alnitak
You can find the query string in window.location.search
您可以在中找到查询字符串 window.location.search

