如何将焦点排除在外 [英] How to exclude Id from focusout

查看:109
本文介绍了如何将焦点排除在外的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Jquery时,只有在设置了focusout时单击聚焦区域外的任何地方才会调用focusout。



如何从激活focusout功能中排除某些id。 ?



例如这里。

您有一个输入文本字段(id =A),它隐藏了一些div的焦点,并在焦点没有显示时显示该div,所以现在很明显当你点击这个(#A)输入字段的任何地方时,将显示div。



问题是,你如何设置一些id(也许是一个选择字段(Id =B旁边)),而不是触发focusout函数。希望它是有道理的。

解决方案

尝试使用 relatedTarget event property:

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

if(e。 relatedTarget& e.relatedTarget.id ==='dontFocusOut'){
return;
}
//做你的事情

});


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 "focusout" function. ?

e.g here.

You have an input text field ( id="A")that hides some div on focus and shows that very div when it's out of focus, so but now it obviously will show the div when you click anywhere out of this ("#A") input field.

Question is, how do you set some id(maybe a select field(Id="B" next to it), not to fire off the "focusout" function. Hope it makes sense.

解决方案

Try using relatedTarget event property:

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

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

});

这篇关于如何将焦点排除在外的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆