仅在元素未获得焦点时执行功能
Execute function only when element is not focused
我的网站上有一个脚本 运行,但我希望它仅在特定元素未获得焦点时执行。这是我的大致想法
window.setInterval(function(){
if (document.getElementById('someElement') != focused) {
doSomething;
}
}, 1000);
"someElement" 设置为可编辑,因此可以单击(聚焦)。
我的问题是“!= focused”在 javascript 中看起来如何。
你可以使用document.activeElement
像这样
if (document.getElementById('someElement') !== document.activeElement)
用它来检查焦点......
window.setInterval(function(){
if (document.getElementById('someElement').is(":focus") {
doSomething;
}
}, 1000);
我的网站上有一个脚本 运行,但我希望它仅在特定元素未获得焦点时执行。这是我的大致想法
window.setInterval(function(){
if (document.getElementById('someElement') != focused) {
doSomething;
}
}, 1000);
"someElement" 设置为可编辑,因此可以单击(聚焦)。
我的问题是“!= focused”在 javascript 中看起来如何。
你可以使用document.activeElement
像这样
if (document.getElementById('someElement') !== document.activeElement)
用它来检查焦点......
window.setInterval(function(){
if (document.getElementById('someElement').is(":focus") {
doSomething;
}
}, 1000);