admin管理员组文章数量:1399269
I am firing some code onblur() of a textbox. But I want to do something different if the user clicked on the cancel button to cause that onblur(). Is there a way within the onblur() event handler function to know what the control is that is about to receive focus and react acordingly?
-Joseph
I am firing some code onblur() of a textbox. But I want to do something different if the user clicked on the cancel button to cause that onblur(). Is there a way within the onblur() event handler function to know what the control is that is about to receive focus and react acordingly?
-Joseph
Share Improve this question edited Jan 30, 2010 at 1:26 Justin Johnson 31.3k7 gold badges66 silver badges89 bronze badges asked Jan 29, 2010 at 23:43 BrokeMyLegBikingBrokeMyLegBiking 5,98815 gold badges52 silver badges66 bronze badges2 Answers
Reset to default 6Yes, you can get the target like this:
var target = event.explicitOriginalTarget || document.activeElement;
(I think I found this on StackOverflow somewhere).
I don't think there is a built in way, but you can hack together something by attaching focus
events to all the form elements and setting some globally accessible variable about who received focus.
Something like this (you may want to fine-tune the time values):
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);
});
本文标签: javascriptOnblurwhat is the next control which will gain focusStack Overflow
版权声明:本文标题:javascript - Onblur, what is the next control which will gain focus? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744158860a2593239.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论