I encountered the problem of bubbling events before, so I searched online, and most of them were the same code, and it was not very smooth to use it. When it comes to FF, you can use e.stopPropagation(); , and somehow I failed to succeed. However, I found that FF supports the writing method of e.cancelBubble = true;, which is feasible after testing. Just post the code here so that you can avoid searching everywhere in the future. The compatibility of previous IE versions has not been tested yet, so I will improve it when I use it.
The code copy is as follows:
//Cancel event bubble
function stopBubble(e) {
var evt = (e) ? e : window.event;//Compatible with FF
evt.cancelBubble = true; //evt.stopPropagation(); to prevent bubbles under FF, it is said to be useful
};
Other:
1. cancelBubble (HTML DOM Event object property): If the event handle wants to prevent the event from propagating to the inclusive object, the property must be set to true.
2. stopPropagation (HTML DOM Event object method): The terminating event is further propagated during the capture, target processing or bubble stage of the propagation process. After calling this method, the handler on the node that handles the event will be called and the event will no longer be dispatched to other nodes.
3. preventDefault (HTML DOM Event object method) notifies the browser not to perform default actions associated with events.
example:
function stopBubble(e)
{
if (e && e.stopPropagation)
e.stopPropagation()
else
window.event.cancelBubble=true
}
Put this stopBubble(e) function into the function you want to prevent the event from bubbled.