如果您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