您的位置:首页 > 其它

做好县级经销商渠道管理以及市场的战略方向

2011-06-30 01:07 447 查看
Event handlers are a common cause of memory leaks and can cause performance degradation when not managed carefully. The more event handlers we create the more likely we are to introduce such problems, so we should try to avoid creating huge numbers of handlers when we don't have to.

Event delegation is a technique where a single event handler is created on a parent element, which leverages the fact that the browser will bubble any events raised on one of its children to this parent element. If the target of the original event matches the delegate's selector then it will execute the event handler, otherwise nothing will happen.

This means that instead of attaching an event handler to each individual child element, we only have to create a single handler on the parent element and then, within the handler, query which child element was actually clicked, and react appropriately.

Example:
<div id='mydiv'>
<li>1</li>
<li>2</li>
<li>3</li>
</div>


Attach an event handler to the list's click event and specify we want to delegate
this event to the list items (that is LI tags), by passing a configuration object to
the on method's fourth argument, containing the delegate property:

Ext.get('mydiv').on('click', function(e, target, options){
alert(target.innerHtml);
}, this, {
delegate: 'li'
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: