jquery - 检查URL上是否存在查询字符串?

时间:2010-07-12 20:58:17

标签: javascript jquery

是否可以使用jquery(或只是javascript)来检查URL上是否存在查询字符串?

4 个答案:

答案 0 :(得分:39)

是的,location对象的属性search包含查询字符串。

alert(window.location.search);

答案 1 :(得分:30)

document.location包含有关网址的信息,document.location.search包含查询字符串,例如?foo=bar&spam=eggs。至于测试它的存在,如何:

if(document.location.search.length) {
    // query string exists
} else {
    // no query string exists
}

不需要jQuery:o

答案 2 :(得分:4)

我认为你可以使用javascript匹配运算符。

var url = window.location.search;
if (url.match("your string").length > 0) {
}

答案 3 :(得分:-3)

查看http://rixi.us/post/791257125/get-and-server-free-dynamic-contet

提取任何查询字符串参数的方法
使用::

if (_GET['key']) {
  var key = _GET['key']
}
相关问题