是否可以跨浏览器找到当前获得焦点的元素?
在 IE 中,可以执行 $(x).blur(function(evt) {alert('Focus gets to ' + evt.toElement.id); });
并且我需要在其他浏览器中执行类似的操作。
作为替代方案,如果可能的话,我可以执行 setTimeout
然后调查当前聚焦的元素,但我也不知道该怎么做。
最佳答案
您只需记住变量中关注的内容即可。 JS 中的变量作用域可以跨浏览器工作:)
(function($){
var focused;
$(commonParentForElements).on('focus','input',function(e){
focused = e.target;
}).on('blur','input',function(e){
//do stuff with focused
//when done, clean up
focused = null;
})
})(jQuery);
关于javascript - 在blur()中如何确定哪个元素获得焦点?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4259904/