REAL防止元素失去焦点 [英] REAL preventing an element from losing focus
问题描述
我试图真正防止DOM元素失去焦点。我已经阅读了一些解决方案,例如:
$ b $ <'>'code> $('input')。on('focusout',function(){
console.log('focus lost');
});
这表明元素正在流失焦点。
所以我的问题是:是否可以实现防止元素失去焦点?像这样?:
$('input')。on('focusout',function(e){
e。如果你想要使用这个方法,你可以使用
$ { >解决方案
没有一种防止元素失去焦点的真正方法。这是因为,当你在浏览器窗口外单击时,元素将始终失去焦点。
你列出的技巧是解决这个问题的一些方法。 b $ b
I am trying to REAL prevent a DOM element from losing focus. I've read some solutions from here e.g.:
But there are only sneaky solutions that (RE)set focus on an element again and again. But when testing this solutions in fiddle i just write simnple:
$('input').on('focusout', function() {
console.log('focus lost');
});
It shows me that element is losing focus.
So my question is: is possible to REAL prevent an element from losing focus? something like this?:
$('input').on('focusout', function(e) {
e.preventDefault()
});
<--this not working but i want to get this result in any other way
There isn't a REAL way for preventing an element from losing focus. It is because than when you click outside browser window, the element will always lose focus.
The trick you listed are some ways to solve this problem.
这篇关于REAL防止元素失去焦点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!