簡體   English   中英

由於我已將mouseover和mouseout事件附加到HTML中的每個元素,如何在幾個HTML元素上阻止相同的事件?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM