繁体   English   中英

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

[英]jquery - check if query string present on URL?

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

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

alert(window.location.search);

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

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

不需要jQuery:o

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

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

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

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

if (_GET['key']) {
  var key = _GET['key']
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM