sometimes i use on
to delegate event ,
dom.addEventListener("click",function(e){
e.target for hander.
}
instead:
dom.on("click",'a',function(){
$(this).handler..
}
so,i guess i can write codes in this way :
function delegate(dom,event,selector,handler){
target = event.target;
while selector.dom.not_match event.target
target = target.parentNode
recheck until match the selector and do handler;
end
}
i had wrote this before:
function delegate(dom,event,selector,handler){
dom.addEvent event function(){
target_arr = dom.find(selector);
if(event.target in_array target_arr){
do handler
}else{
target = target.parentNode until dom.
recheck in target_arr;
}
}
}
someone know how jquery's work method on 'delegate' or 'on' for delegate?please show me the code simply description for 'delegate'..thanks alot.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…