如何选择一个关注它的元素与jQuery [英] How to select an element that has focus on it with jQuery
本文介绍了如何选择一个关注它的元素与jQuery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何选择具有当前焦点的元素?
How can you select an element that has current focus?
在jQuery中没有:focus
,这就是为什么我们可以使用这样的东西:
There is no :focus
filter in jQuery, that is why we can use something like this:
$('input:focus').someFunction();
推荐答案
真正最好的方法是onFocus事件的处理程序,然后将变量设置为具有焦点的元素的ID。
Really the best way to do it is to setup a handler for the onFocus event, and then set a variable to the ID of the element that has focus.
如下所示:
var id;
$(":input").focus(function () {
id = this.id;
});
这篇关于如何选择一个关注它的元素与jQuery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文