我应该使用哪个JavaScript库来解析URL参数? [英] What JavaScript library should I use for parsing URL parameters?
问题描述
如何解析JavaScript中的URL参数?(这些参数通常称为GET参数或CGI参数,但在这种情况下,页面基本上是提交给自身而不是服务器,因此没有GET请求,也绝对没有CGI程序.)
How do I parse URL parameters in JavaScript? (These are the parameters I would ordinarily call GET parameters or CGI parameters, but in this case the page is basically submitting to itself, not a server, so there is no GET request and definitely no CGI program.)
我已经在网上看到了许多可以复制的例程,但是我不知道它们中的任何一个多么健壮.我已经习惯了Perl和Java等其他语言,在这些语言中,我可以依靠经过严格测试和健壮的库,据我所知,该库可以处理标准中数百万个小巧的情况.我在这里也希望如此,而不仅仅是剪切和粘贴示例.
I've seen a number of routines on the net that I can copy, but I have no idea how robust any of them are. I'm used to other languages like Perl and Java where I can rely on an extremely well-tested and robust library that I know will handle millions of little edge-cases in the standard. I would like the same here, rather than just cutting and pasting an example.
推荐答案
Here's are two simple functions that do the job : http://adamv.com/dev/javascript/querystring
以下是API参考的示例:
Here is a sample of the API Reference :
var qs = new Querystring();
// Parse a given querystring
var qs2 = new Querystring("name1=value1&name2=value2");
var v1 = qs2.get("name1");
var v3 = qs2.get("name3", "default value");
这篇关于我应该使用哪个JavaScript库来解析URL参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!