gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 22:54:01 24 4
gpt4 key购买 nike

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

$(".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();
}
});

最佳答案

我想你会喜欢这个值:

var queryString = window.location.search;

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

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

关于jquery 检查 URL 是否有查询字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8920930/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com