Stopping propagation of mousedown/mouseup from a click handler

后端 未结 1 980
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-31 02:42

Here\'s a DEMO.

I have two divs, an inner and an outer:

相关标签:
1条回答
  • 2020-12-31 03:27

    Yes. Since mouseclick and mousedown/mouseup are different events, you can't get at one from the other at all - you have to do it from within your own mousedown/mouseup handlers. What you can do is refactor that into a generic method to use in both places:

    stopPropagation('#inner', 'mousedown');
    stopPropagation('#inner', 'mouseup');
    
    function stopPropagation(id, event) {
        $(id).on(event, function(e) {
            e.stopPropagation();
            return false;
        });
    }
    
    0 讨论(0)
提交回复
热议问题