How to exclude Id from focusout

前端 未结 2 811
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-23 03:16

With Jquery, focusout is just called when you click anywhere out of the focused area when \"focusout\" is set.

How do I exclude some id(s) from activiting the \"focusou

相关标签:
2条回答
  • 2021-01-23 04:00

    Try using relatedTarget event property:

    $('#id').focusout (function (e) {
    
        if (e.relatedTarget && e.relatedTarget.id === 'dontFocusOut') {
            return;
        }
        //do your thing
    
    });
    
    0 讨论(0)
  • 2021-01-23 04:05

    You can unbind the focusout when you click on a div. This may return some expected results, and at some point in your code you'll probably want to rebind it. See here for an example: http://jsfiddle.net/hdCFA/

    $("input").on("focus", function() {
        $(".hidden").show();
    });
    $("input").on("focusout",function() {
        $(".hidden").hide();
    });
    
    $(".clickable").on("mousedown", function() { 
        $("input").unbind("focusout"); 
    });
    

    HTML:

    <input />
    <div class="hidden">Hidden div</div>
    <div class="clickable">Click me</div>
    

    CSS:

    .clickable { background:blue; }
    .hidden {
        display:none;
    }
    
    0 讨论(0)
提交回复
热议问题