繁体   English   中英

如果为空,则添加/附加查询字符串

[英]Add/Append query string if empty jquery/javascript

如何在准备好文档后附加查询字符串,例如?a=0 它必须首先检查是否存在现有查询字符串。 仅当查询字符串不存在时,才应追加查询字符串。 否则,它什么都不做。

if(!(window.location.search.indexOf("?a=0") > -1)) {
    window.location.href += window.location.search;
}
if ( !window.location.search.trim().length ) 
   window.location.href = window.location.href + '?a=0';

尝试这个:

$( document ).ready(function() {

    url = window.location;  //get current url
    if(url.indexOf("?a=") == -1){ //check for ?a= 
     document.location = url+"?a=0"; // redirect it
    }

});

暂无
暂无

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

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