自定义事件的绑定与触发实现!
<!DOCTYPE html><html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><script src="jquery-1.8.3.js"></script><script> var eventWrap={};var eventIdKey='eventId'+new Date().getTime();var uuid=0;function bind($el,eName,func){if($el && eName && func){var eId=$el.attr(eventIdKey);if(!eId){eId='eid'+(++uuid);$el.attr(eventIdKey,eId);eventWrap[eId]={};}var fArr=eventWrap[eId][eName];if(!fArr){fArr=eventWrap[eId][eName]=[];}fArr.push(func);}}function trigger($el,eName){if($el && eName){var eId=$el.attr(eventIdKey);if(eId){var fArr=eventWrap[eId][eName];if(fArr){ for(var i=0;i<fArr.length;i++){if(typeof fArr[i]=='function'){fArr[i].call($el);}}}}}}$(function(){//测试var $div=$('div.tdiv');bind($div,'aaa',function(){alert(111);});bind($div,'aaa',function(){alert(222);});trigger($div,'aaa');});</script></head><body><div class="tdiv"></div></body></html>