How to exclude Id from focusout

限于喜欢 提交于 2019-12-02 04:24:02

Try using relatedTarget event property:

$('#id').focusout (function (e) {

    if (e.relatedTarget && e.relatedTarget.id === 'dontFocusOut') {
        return;
    }
    //do your thing

});

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;
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!