相思资源网 Design By www.200059.com
使用示例:
复制代码 代码如下:
var qs = new QueryString(query);
qs.set("ajaxids", ids)
qs.set("ajaxsn", new Date())
query = qs.toStr();

也可以连续调用:
复制代码 代码如下:
query = new QueryString(query).set("ajaxids", ids).set("ajaxsn", new Date()).toStr();

其它用法就自己看代码琢磨吧。
完整代码:
复制代码 代码如下:
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;
    };
};
标签:
QueryString,JavaScript

相思资源网 Design By www.200059.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
相思资源网 Design By www.200059.com

评论“JavaScript QueryString解析类代码”

暂无JavaScript QueryString解析类代码的评论...