Fengzhimei@Dot.Net
Designing My Colorful Dream
随笔 - 78,  文章 - 0,  评论 - 196,  阅读 - 15万

Used to add your querystring to an URL, it can judge if the querystring you try to add is exist in the URL, if so, replace it with new value, or expand the URL.

function ExpandQS(queryStringName, queryStringValue)
{
    
var returnValue;
    
var currHref = window.location.href.substring(0,(window.location.href.length-window.location.search.length));
    
var currQuery = window.location.search.substring(1);
    
var args = currQuery.split('&');
    
var keyValuePairs = new Object();
    
if(currQuery) {
        
for(var i=0; i < args.length; i++{
            
var value;
            
var pair = args[i].split('=');
            
var name = unescape(pair[0]);

            
if (pair.length == 2){
                value 
= unescape(pair[1]);
            }

            
else{
                value 
= name;
            }
      
            keyValuePairs[name] 
= value;
        }

        
        keyValuePairs[queryStringName] 
= queryStringValue;
        
        
var newQuery = "";
        
        
for(var key in keyValuePairs){
            newQuery 
+= key + "=" + keyValuePairs[key] + "&";
        }

        
        newQuery 
= newQuery.substring(0, newQuery.length - 1);
        
        returnValue 
= currHref + "?" + newQuery;
    }

    
else{
        returnValue 
= currHref + "?" + queryStringName + "=" + queryStringValue;
    }

    
return returnValue;
}

Hopefully, it's useful to you.
posted on   fengzhimei  阅读(838)  评论(0编辑  收藏  举报
努力加载评论中...

点击右上角即可分享
微信分享提示