Onblur,下一个将获得关注的控件是什么?

我正在触发文本框的一些代码onblur()。 但是如果用户点击取消按钮导致onblur(),我想做一些不同的事情。 在onblur()事件处理函数中是否有一种方法可以知道控件是什么,即将获得焦点并进行相应的反应?

-约瑟夫

是的,您可以像这样获得目标:

var target = event.explicitOriginalTarget || document.activeElement; 

(我想我在StackOverflow上找到了这个)。

我不认为有内置方式,但你可以通过将focus事件附加到所有表单元素并设置一些关于谁获得焦点的全局可访问变量来组合一些东西。

像这样的东西(你可能想要微调时间值):

 var focusedElem = null; var focusedTime = 0; $("input", "#myForm").focus(function() { focusedElem = this; focusedTime = new Date(); }) .blur(function() { setTimeout(function() { //set a small timeout to wait for the other control to receive focus and set itself as focusedElem if (focusedElem && (new Date() - focusedTime) < 15) { //do Something with focusedElem; } }, 10); });