我需要知道文本区域是否处于焦点。我正在做这样的事情:
if (document.activeElement === 'textarea') {
console.log('You are in a textarea');
}
最佳答案
检查标签名称
if (document.activeElement.tagName.toLowerCase() === 'textarea') {
console.log('You are in a textarea');
}
关于javascript - 如何使用 dom 元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20870326/