jquery检查URL是否有查询字符串

Anj*_*apa 5 string url jquery

如果它第一次访问该网站并且没有添加任何查询,或者如果只有一个查询字符串附加到网址'?hos',如http://hospitalsite/events/Pages/default.aspx?hos = somevalue,那么我需要应用if条件..其他条件工作正常..如何查看是否有查询

$(".hospitalDropDown").change(function(e){
  currentURL=$(location).attr('href');
  if((currentURL == 'http://hospitalsite/events/Pages/default.aspx' or (....)) {
    window.location.href= 'http://hospitalsite/events/Pages/default.aspx'+'?hos='+$(this).val();
  } else {
    window.location.href = ( $(this).val() == "All Hospitals" ) ? 'http://hospitalsite/events/Pages/default.aspx': currentURL +'&hos='+ $(this).val(); 
  }
});
Run Code Online (Sandbox Code Playgroud)

Cᴏʀ*_*ᴏʀʏ 22

我想你喜欢这个价值:

var queryString = window.location.search;
Run Code Online (Sandbox Code Playgroud)

如果您的网址是"http://www.google.com/search?q=findme",则上述queryString变量将等于"?q = findme".

您可以检查是否为非空,以查看是否存在查询字符串.