Skip to content
字数
70 字
阅读时间
1 分钟
js
class jQuery {

    constructor(selector) {

        const result = document.querySelectorAll(selector)

        const length = result.length;

        for (let i = 0; i < length; i++) {

            this[i] = result[i]

        }

        this.length = length;

        this.selector = selector;

  

    }

    get(index) {

        return this[index]

    }

    each(fn) {

        for (let i = 0; i < this.length; i++) {

            const eleme = this[i]

            fn(eleme)

        }

    }

    on(type,fn,index2){

        this.index2= index2;

        this[index2].addEventListener(type,fn)

    }

  

}

贡献者

The avatar of contributor named as sunchengzhi sunchengzhi

文件历史

撰写