阅读背景:

JavaScript 类库起手式 ——万元归一

来源:互联网 
    /**
     * selector     选择器
     * content      上下文
     * index        元素位置
     */
    function $(selector, context, index) {
        return new $.prototype.init(selector, context, index);
    };
    $.prototype.init = function (selector, context, index) {
        this.index = index;
        this.context = context || document;
        if (selector && selector.nodeType) {
            this[0] = selector;
            this.length = 1;
            return this;
        } else if (/^#|^./.test(selector)) { 
            this.selector = selector
            $.nodeList = this.context.querySelectorAll(selector);
            this.length = $.nodeList.length;
            for (var i = 0; i < this.length; i++) {
                this[i] = $.nodeList[i];
            }
        } else {
            return this;
        }
    };
    $.fn = $.prototype.init.prototype = {};    /**
     * selector     选择器
     * cont



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: