admin管理员组文章数量:1410697
I'm developing a virtual keyboard in jQuery and my problem is:
When I click on a key of the keyboard the input loses the focus during the click, and if the number of letters in the input is longer than the input size, the input shows the beginning of the string. And then when the click is released the input gets back the focus and the caret es to the end of the string. So it's quite ugly because we have the impression that the input contents blink.
theButtonDiv.click(function() {
attachedInput.value = idOfAttachedInput.value + theActualKey;
attachedInput.focus();
});
So I would like to prevent the input from losing the focus when we clicked on a button of the keyboard.
How can I do this?
Thanks.
I'm developing a virtual keyboard in jQuery and my problem is:
When I click on a key of the keyboard the input loses the focus during the click, and if the number of letters in the input is longer than the input size, the input shows the beginning of the string. And then when the click is released the input gets back the focus and the caret es to the end of the string. So it's quite ugly because we have the impression that the input contents blink.
theButtonDiv.click(function() {
attachedInput.value = idOfAttachedInput.value + theActualKey;
attachedInput.focus();
});
So I would like to prevent the input from losing the focus when we clicked on a button of the keyboard.
How can I do this?
Thanks.
Share Improve this question edited Jun 22, 2011 at 19:01 Michael Myers♦ 192k47 gold badges298 silver badges295 bronze badges asked Jun 22, 2011 at 13:36 Stack bugStack bug 611 silver badge3 bronze badges 2- 1 You could try using .setInterval and have the function set the focus to the relevant textbox. In terms of ease of setting up this would be relatively painless, but I'm willing to bet there are more succinct answers out there. – MoarCodePlz Commented Jun 22, 2011 at 13:38
- 1 You may simply need to be setting the cursor/caret position instead of focusing the field. Check out this related question. – hughes Commented Jun 22, 2011 at 19:12
2 Answers
Reset to default 7One way is to listen for the "mousedown" event on the top level keyboard node and call preventDefault
on the event object.
I think you're looking for a CSS property called outline
.
#yourinput {
outline: none;
}
That should take care of the box being highlighted when it has focus.
本文标签: javascriptPrevent losing focus when click out of an inputStack Overflow
版权声明:本文标题:javascript - Prevent losing focus when click out of an input - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745042180a2639143.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论