Home  >  Article  >  Web Front-end  >  JavaScript QueryString parsing class code_javascript skills

JavaScript QueryString parsing class code_javascript skills

WBOY
WBOYOriginal
2016-05-16 18:36:21990browse
Usage example:
Copy code The code is as follows:

var qs = new QueryString(query);
qs.set("ajaxids", ids)
qs.set("ajaxsn", new Date())
query = qs.toStr();

can also be called continuously:
Copy code The code is as follows:

query = new QueryString(query).set("ajaxids", ids).set("ajaxsn", new Date()).toStr();

You can use it yourself for other uses Let’s look at the code and figure it out.
Full code:
Copy 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);
                                                                                                                                                     for (var I = 0; i & lt; a.Length; i) {
var T = a [i] .split ('='); ]);
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]) '&';

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn