我为信息亭应用程序创建了一个自定义虚拟键盘。问题是每次单击键盘按键时,输入字段都会失去焦点。 任何帮助,将不胜感激。
最佳答案
You can shift the focus back as soon as the input loses out the focus on click on the virtual keyboard.
let input = document.getElementById('input')
input.focus() // focus on input on page load
function handleInput (key) {
input.value += key // add key value to input
}
<button onclick="handleInput('a')">a</button>
<button onclick="handleInput('b')">b</button>
<button onclick="handleInput('c')">c</button>
<input onfocusout="this.focus()" id="input"/> <!-- focus on input back on onfocusout ie. when user click elsewhere -->
输入始终处于焦点。
关于javascript - 防止输入因虚拟键盘点击而失去焦点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60265272/