This article mainly introduces the simple method of preventing bubbling events and default events in JS. Friends in need can refer to it
If
is inside
, then what? ,
has an onclick event,
also has an onclick event. In order to trigger the click event of
without triggering the click event of the parent element, you need to call the following function:
function stopBubble(e){ if(e&&e.stopPropagation){//非IE e.stopPropagation(); } else{//IE window.event.cancelBubble=true; } }
function stopDefault( e ) { //阻止默认浏览器动作(W3C) if ( e && e.preventDefault ) e.preventDefault(); //IE中阻止函数器默认动作的方式 else window.event.returnValue = false; return false; }
The above is the entire content of this chapter, more For more related tutorials, please visit JavaScript Video Tutorial!