How to trigger the click time of li tag and a tag at the same time (involving JS default event, bubbling, capture)

Reference author presents: http://caibaojian.com/javascript-stoppropagation-preventdefault.html

All #menus1 li in the page are bound to the click() event. The requirement is to trigger the click time of <li> and the <a> tag under <li> when the <li> menu is clicked, and <li>click is for <li>The class tag is selected and the <a> tag click opens the page. The problem is that the event of the <a> tag is triggered but the time of the <li> tag is not triggered?

Find:

$("#testC").on('click',function(){
return false;
});

The meaning of return false; in JQuery is to prevent the default behavior and bubbling of the event, so the click event of the upper label is not successfully triggered, and finally changed to

Only prevent the default behavior:

//阻止浏览器的默认行为 
function stopDefault( e ) { 
    //阻止默认浏览器动作(W3C) 
    if ( e && e.preventDefault ) 
        e.preventDefault(); 
    //IE中阻止函数器默认动作的方式 
    else 
        window.event.returnValue = false; 
    return false; 
}

 

Guess you like

Origin blog.csdn.net/a1_HelloWord/article/details/106722926