防止点击输入时失去焦点
我正在 jQuery 中开发一个虚拟键盘,我的问题是:
当我单击键盘上的某个键时,输入在单击期间失去焦点,并且如果输入中的字母数比输入大小长,则输入显示字符串的开头。然后,当释放单击时,输入重新获得焦点,并且插入符号到达字符串的末尾。所以它很丑陋,因为我们的印象是输入内容会闪烁。
theButtonDiv.click(function() {
attachedInput.value = idOfAttachedInput.value + theActualKey;
attachedInput.focus();
});
所以我想防止当我们点击键盘按钮时输入失去焦点。
我该怎么做?
谢谢。
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 comes 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
一种方法是侦听顶级键盘节点上的“mousedown”事件,并在事件对象上调用
preventDefault
。One way is to listen for the "mousedown" event on the top level keyboard node and call
preventDefault
on the event object.我认为您正在寻找名为
outline
的 CSS 属性。这应该可以解决当框具有焦点时突出显示的问题。
I think you're looking for a CSS property called
outline
.That should take care of the box being highlighted when it has focus.