[英]How can I prevent the default event action when an event handler is attached to a parent HTML element?
[英]Since I have attached mouseover and mouseout event to each and every element in HTML, How can I prevent same event on few HTML element?
$('body').on('mouseover mouseout', '*:not(.printToolBar)', function (e) {
if (this === e.target) {
(e.type === 'mouseover' ? setMenuBox(e.target) : removeMenuBox(e.target));
}
});
我曾嘗試.on
和.off
方法還,但沒能得到期望的結果。
只需從原始綁定中排除不需要的元素:
$('body').on('mouseover mouseout', '*:not(.undesiredelements)', function (e) {
if (this === e.target) {
$(e.target).css('border', (e.type === 'mouseover' ? '1px solid blue' : ''));
}
});
“刪除某些元素的綁定”等同於更改觸發處理程序的選擇器條件。 如果在使用像*
類的松散選擇器之后需要更改綁定,則可以簡單地取消綁定原始處理程序並重新綁定到所需的元素。
請注意,這里只發生一個事件處理程序綁定(即對於body
元素)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.