如何知道文本框Usinf Java脚本的焦点 [英] How to know focus of Text Box Usinf Java script

查看:59
本文介绍了如何知道文本框Usinf Java脚本的焦点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果(document.getElementById(``TextBox1'').focus()== true)
//要在此处检查焦点为文本框.. ??
////不检查条件.

if (document.getElementById(''TextBox1'').focus()== true)
// want to check focus fo text box here ..??
// not checking if condition.

推荐答案

问题编写得不正确,但是您似乎想在给定的时间找到焦点所在的控件.

您可以尝试以下任何一种方法:
1.使用JS中的document.activeElement属性了解当前关注的元素.相应地使用它.
2.使用jQuery选择器:focus,例如:
Question not written properly, but looks like you want to find the control in focus at a given time.

You can try either of these:
1. Use document.activeElement property in JS to know the currently focused element. Use it accordingly.
2. Use jQuery selector :focus, example:
var element = document.querySelector(":focus");


这篇关于如何知道文本框Usinf Java脚本的焦点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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