Pro*_*cop 28 javascript jquery
是否可以使用jquery(或只是javascript)来检查URL上是否存在查询字符串?
Fel*_*ing 39
是的,该location
对象具有search
包含查询字符串的属性.
alert(window.location.search);
Run Code Online (Sandbox Code Playgroud)
Mat*_*chu 31
document.location
包含有关URL的信息,并document.location.search
包含查询字符串,例如?foo=bar&spam=eggs
.至于测试它的存在,如何:
if(document.location.search.length) {
// query string exists
} else {
// no query string exists
}
Run Code Online (Sandbox Code Playgroud)
不需要jQuery:o
小智 5
我认为您可以使用 javascript 匹配运算符。
var url = window.location.search;
if (url.match("your string").length > 0) {
}
Run Code Online (Sandbox Code Playgroud)