jQuery 1.0.2

2020-05-23 06:10:44易采站长站整理

    },
    grep: function(elems, fn, inv) {
        // If a string is passed in for the function, make a function
        // for it (a handy shortcut)
        if ( fn.constructor == String )
            fn = new Function(“a”,”i”,”return ” + fn);
        var result = [];
        // Go through the array, only saving the items
        // that pass the validator function
        for ( var i = 0; i < elems.length; i++ )
            if ( !inv && fn(elems[i],i) || inv && !fn(elems[i],i) )
                result.push( elems[i] );
        return result;
    },
    map: function(elems, fn) {
        // If a string is passed in for the function, make a function
        // for it (a handy shortcut)
        if ( fn.constructor == String )
            fn = new Function(“a”,”return ” + fn);
        var result = [];
        // Go through the array, translating each of the items to their
        // new value (or values).
        for ( var i = 0; i < elems.length; i++ ) {
            var val = fn(elems[i],i);
            if ( val !== null && val != undefined ) {
                if ( val.constructor != Array ) val = [val];