使用 jQuery,我可以像这样测试输入字段是否具有焦点:
if ($("...").is(":focus")) {
...
}
不使用 jQuery 如何做到这一点?
最佳答案
这里回答了这个问题:Javascript detect if input is focused
摘自上面的回答:
this === document.activeElement // where 'this' is a dom object
关于javascript - 检查输入字段是否在 vanilla JavaScript 中具有焦点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30714871/