document.activeelement返回正文 [英] document.activeelement returns body

查看:83
本文介绍了document.activeelement返回正文的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<input id="text1" tabindex="1" onblur="invokeFunc()"/>
<input id="text2" tabindex="2" onblur="invokeFunc()"/>

function invokeFunc(){
   // ajax request 
   alert(document.activeElement); 
   // this returns body element in firefox, safari and chrome.
}

我正在尝试在设置了适当tabindex的文本框上设置焦点onblur。

i am trying set focus onblur on text boxes with proper tabindex set.

当我调用javascript函数onblur并尝试获取document.activeelement时,它总是返回body元素而不是active元素。

when i invoke javascript function onblur and try to get document.activeelement then it always return me body element instead of active element where focus is.

推荐答案

演示: http://jsfiddle.net/u3uNP/

这篇关于document.activeelement返回正文的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆