简体   繁体   English

检测何时更改了当前选定的元素

[英]Detect when the currently selected element is changed

I've got a form with a number of fields on it. 我有一个表格,上面有很多字段。 I need to be able to tell when the user has selected a different field. 我需要能够分辨出用户何时选择了其他字段。

Currently, I've been using the following: 目前,我一直在使用以下内容:

 $(document).on('focus click', function () {
        //...
    });

However this only works for clicking fields. 但是,这仅适用于单击字段。 If I tab through the fields, I'm not able to detect any changes. 如果我在各个字段之间切换,则无法检测到任何更改。

I had thought .on('focus') would handle tabbing through fields, but I was apparently wrong. 我以为.on('focus')可以处理字段之间的制表符,但是我显然错了。 Is there a simpler way of detecting focus change across a full page, rather than individual elements? 有没有一种更简单的方法来检测整个页面而不是单个元素的焦点变化?

Use jQuery to select the input elements not the document 使用jQuery选择输入元素而不是 document

$('input').on('focus', function () { //... });

Tabbing through should work. 逐步浏览应该起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM