查找当前是否选择了文本框 [英] Find if a textbox is currently selected

查看:133
本文介绍了查找当前是否选择了文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎么会发现如果一个文本框(或textarea)目前在焦点?我不在乎知道它是哪一个,我只需要知道一个是否在焦点(有光标在其中)。如何使用JavaScript和jQuery来做到这一点?

解决方案

因为您已经找到 document.activeElement ,你可以检查它的nodeName。

  if(document.activeElement.nodeName =='TEXTAREA'|| document.activeElement.nodeName =='INPUT'){
// ....
}

类似的东西。


How would I find if a textbox (or textarea) currently is in focus? I don't care to know which one it is, I just need to know if one is in focus (has the cursor in it). How would I do this with javascript and jquery?

解决方案

Since you have found document.activeElement, you can check its nodeName.

if (document.activeElement.nodeName == 'TEXTAREA' || document.activeElement.nodeName == 'INPUT') {
    // ....
}

Something like that.

这篇关于查找当前是否选择了文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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