[英]How can I get the id of the focused textbox?
I am creating a Chrome extension and I need to get the id of the selected textbox on the page.我正在创建一个 Chrome 扩展程序,我需要获取页面上所选文本框的 id。 I am using Javascript and jQuery
我正在使用 Javascript 和 jQuery
You can use the :focus
pseudo-class selector.您可以使用
:focus
伪类选择器。 for instance: $("input:focus")
will get the focused input.例如:
$("input:focus")
将获得焦点输入。
Here is how you can get the id
using pure javascript
:-这是使用纯
javascript
获取id
的方法:-
document.activeElement.getAttribute('id')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.