A previously written JS class that parses QueryString. You can get or set the value in QueryString, and noted down the value for convenience :)
Example:
The Code is as follows:
Var qs = new QueryString (query );
Qs. set ("ajaxids", ids)
Qs. set ("ajaxsn", new Date ())
Query = qs. toStr ();
It can also be called consecutively:
The Code is as follows:
Query = new QueryString (query). set ("ajaxids", ids). set ("ajaxsn", new Date (). toStr ();
For other usage, let's take a look at the code.
Complete code:
The Code is as follows:
QueryString = function (qs ){
This. p = {};
If (! Qs)
Url = location. search;
If (qs ){
Var B = qs. indexOf ('? ');
Var e = qs. indexOf ('#');
If (B> = 0 ){
Qs = e <0? Qs. substr (B + 1): qs. substring (B + 1, e );
If (qs. length> 0 ){
Qs = qs. replace (/\ +/g ,'');
Var a = qs. split ('&');
For (var I = 0; I <a. length; I ++ ){
Var t = a [I]. split ('= ');
Var n = decodeURIComponent (t [0]);
Var v = (t. length = 2 )? DecodeURIComponent (t [1]): n;
This. p [n] = v;
}
}
}
}
This. set = function (name, value ){
This. p [name] = value;
Return this;
};
This. get = function (name, def ){
Var v = this. p [name];
Return (v! = Null )? V: def;
};
This. has = function (name ){
Return this. p [name]! = Null;
};
This. toStr = function (){
Var r = '? ';
For (var k in this. p ){
R + = encodeURIComponent (k) + '=' + encodeURIComponent (this. p [k]) + '&';
}
Return r;
};
};