1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | var aQuery = function (selector){ // 强制为对象 if (!(this instanceof aQuery)){ return new aQuery(selector) } var elem = document.getElementById(/[^ #].*/.exec(selector)[0]); this.length = 1; this[0] = elem; this.context = document; this.selector = selector; this.get = function (num){ return this[num]; } return this } |
既可通过aQuery("#book")[0] / aQuery("#book").get(0) 获取到元素