如果您Container22是可以有焦点的元素,你可以检查它是否已集中在模糊事件:
$('#container21').blur(function(){
// timeout because focus does not switch immediately
setTimeout(function(){
if (document.activeElement === document.getElementById('container22')) {
// your logic here: container22 has focus
} else {
// your logic here: container22 does not have focus
}
}, 60);
});
如果Container22不能具有焦点,你可以给它一个类来代替:
$('#container22').click(function(){
$(this).addClass('fake-focus');
});
您删除该类时Container21获得焦点:
$('#container21').focus(function(){
$('#container22').removeClass('fake-focus');
});
你检查FO当Container21失去焦点时 - 如果Container22具有该类,则表示用户单击它以集中注意力。我们需要再次超时,因为焦点丢失后,点击事件将发生。
$('#container21').blur(function(){
// timeout because focus does not switch immediately
setTimeout(function(){
if ($('#container22').hasClass('fake-focus')) {
// your logic here: container22 was clicked
} else {
// your logic here: container22 was not clicked
}
}, 60);
});
e.target与条件? – guradio
@guradio e.target给我绑定聚焦事件相同的div,即使我从div的外部点击。 –
您可以共享可执行文件演示/代码片段或[JSFiddle](https://jsfiddle.net/)吗? – Rayon