functioneventfn(e){ var e = e || window.event; var target = e.target || e.srcElement; if (matchSelector(target, selector)) { if(fn) { fn.call(target, e); } } } } /** * only support #id, tagName, .className * and it's simple single, no combination */ functionmatchSelector(ele, selector) { // if use id if (selector.charAt(0) === '#') { return ele.id === selector.slice(1); } // if use class if (selector.charAt(0) === '.') { return (' ' + ele.className + ' ').indexOf(' ' + selector.slice(1) + ' ') != -1; } // if use tagName return ele.tagName.toLowerCase() === selector.toLowerCase(); }