[英]Stop input from losing focus on Virtual keyboard click
我為自助服務終端應用程序創建了一個自定義虛擬鍵盤。 問題是每次單擊鍵盤鍵時,輸入字段都會失去焦點。 任何幫助,將不勝感激。
阻止聚焦元素然后將焦點返回到所需的字段。
$('#div').on('mousedown', function(event) {
event.preventDefault();
$('#field').focus();
});
一旦輸入在虛擬鍵盤上失去焦點,您就可以將焦點移回。
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 -->
輸入始終是焦點。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.