REAL防止元素失去焦点 [英] REAL preventing an element from losing focus

查看:107

没有一种防止元素失去焦点的真正方法。这是因为,当你在浏览器窗口外单击时,元素将始终失去焦点。



你列出的技巧是解决这个问题的一些方法。 b $ b

I am trying to REAL prevent a DOM element from losing focus. I've read some solutions from here e.g.:

StackOverflow solution 1

StackOverflow solution 2

StackOverflow solution 3

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆