stopPropogration 与 .toggle() 和 jQuery

stopPropogration with .toggle() and jQuery

希望将 stopPropogation 添加到以下下拉菜单中。

$(document).ready(function() {$('.js nav #nav-ads').toggle(
function() { 
    $('.dropdown-js').fadeIn();
    $('.js nav #nav-ads span').toggleClass('arrow-up').toggleClass('arrow-down');
},
function() { 
    $('.dropdown-js').fadeOut();
    $('.js nav #nav-ads span').toggleClass('arrow-down').toggleClass('arrow-up');
}
); 

});

Note: This method signature was deprecated in jQuery 1.8 and removed in jQuery 1.9. jQuery also provides an animation method named .toggle() that toggles the visibility of elements. Whether the animation or the event method is fired depends on the set of arguments passed. jQuery API


现代解决方案

$('.js nav #nav-ads').on('click', function (e) {
    $('.dropdown-js').fadeToggle();
    $('.js nav #nav-ads span').toggleClass('arrow-up arrow-down');
    e.stopPropagation();
});