Stop just one dropdown toggle from closing on click

前端 未结 7 2207
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-13 08:58

I have a button dropdown (just one, not all of them), and inside of it, I want to have several input field where people can type stuff inside without the dropdown hiding as

7条回答
  •  庸人自扰
    2020-12-13 09:08

    Actually, if you were in Angular.js, it would be more elegant to make a directive for it:

    app.directive('stopClickPropagation', function() {
        return {
            restrict: 'A',
            link: function(scope, element) {
                element.click(function(e) {
                    e.stopPropagation();
                });
            }
        };
    });
    

    And then, on the dropdown-menu, add the directive:

    Especially if you want to stop propagation for multiple mouse events:

    ...
    element.click(function(e) {
        e.stopPropagation();
    });
    
    element.mousedown(...
    element.mouseup(...
    ...
    

提交回复
热议问题