jquery param

function fn_aa(){
var         
    core_toString = Object.prototype.toString,
    core_hasOwn = Object.prototype.hasOwnProperty,
    class2type = {},
jQuery = { 
    isFunction: function (obj) {
        return jQuery.type(obj) === "function";
    },
    isArray: function (obj) {
        return jQuery.type(obj) === "array";
    },
    isWindow: function (obj) {
        return obj != null && obj == obj.window;
    },
    isNumeric: function (obj) {
        return !isNaN(parseFloat(obj)) && isFinite(obj);
    },
    type: function (obj) {
        return obj == null ?
            String(obj) :
            class2type[core_toString.call(obj)] || "object";
    },
    isPlainObject: function (obj) {        
        if (!obj || jQuery.type(obj) !== "object" || obj.nodeType || jQuery.isWindow(obj)) {
            return false;
        }
        try {            
            if (obj.constructor &&
                !core_hasOwn.call(obj, "constructor") &&
                !core_hasOwn.call(obj.constructor.prototype, "isPrototypeOf")) {
                return false;
            }
        } catch (e) {            
            return false;
        } 
        var key;
        for (key in obj) { }
        return key === undefined || core_hasOwn.call(obj, key);
    },
    isEmptyObject: function (obj) {
        var name;
        for (name in obj) {
            return false;
        }
        return true;
    },   
    each: function (obj, callback, args) {
        var name,
            i = 0,
            length = obj.length,
            isObj = length === undefined || jQuery.isFunction(obj);

        if (args) {
            if (isObj) {
                for (name in obj) {
                    if (callback.apply(obj[name], args) === false) {
                        break;
                    }
                }
            } else {
                for (; i < length;) {
                    if (callback.apply(obj[i++], args) === false) {
                        break;
                    }
                }
            }         
        } else {
            if (isObj) {
                for (name in obj) {
                    if (callback.call(obj[name], name, obj[name]) === false) {
                        break;
                    }
                }
            } else {
                for (; i < length;) {
                    if (callback.call(obj[i], i, obj[i++]) === false) {
                        break;
                    }
                }
            }
        }
        return obj;
    }
}; 
jQuery.each("Boolean Number String Function Array Date RegExp Object".split(" "), function(i, name) {
    class2type[ "[object " + name + "]" ] = name.toLowerCase();
}); 
var r20 = /%20/g,
rbracket = /\[\]$/,
rselectTextarea = /^(?:select|textarea)/i;
 
jQuery.param = function( a ) {
    var prefix,
        s = [],
        add = function( key, value ) {            
            value = jQuery.isFunction( value ) ? value() : ( value == null ? "" : value );
            s[ s.length ] = encodeURIComponent( key ) + "=" + encodeURIComponent( value );
        }; 
    if ( jQuery.isArray( a ) || ( a.jquery && !jQuery.isPlainObject( a ) ) ) {         
        jQuery.each( a, function() {
            add( this.name, this.value );
        });
    } else {        
        for ( prefix in a ) {
            buildParams( prefix, a[ prefix ], false, add );
        }
    }     
    return s.join( "&" ).replace( r20, "+" );
};

function buildParams( prefix, obj, traditional, add ) {
    var name;

    if ( jQuery.isArray( obj ) ) {     
        jQuery.each( obj, function( i, v ) {
            if ( traditional || rbracket.test( prefix ) ) {                 
                add( prefix, v );
            } else {                 
                buildParams( prefix + "[" + ( typeof v === "object" ? i : "" ) + "]", v, traditional, add );
            }
        });

    } else if ( !traditional && jQuery.type( obj ) === "object" ) {         
        for ( name in obj ) {
            buildParams( prefix + "[" + name + "]", obj[ name ], traditional, add );
        }
    } else {     
        add( prefix, obj );
    }
};
return jQuery;
 }
 

猜你喜欢

转载自blog.csdn.net/LU142857/article/details/83412849
今日推荐