如何获取焦点文本框的 id?

How can I get the id of the focused textbox?

我正在创建一个 Chrome 扩展,我需要获取页面上所选文本框的 ID。 我正在使用 Javascript 和 jQuery

您可以使用 :focus 伪 class 选择器。 例如: $("input:focus") 将获得焦点输入。

以下是使用纯 javascript 获得 id 的方法:-

document.activeElement.getAttribute('id')