简体   繁体   English

专注于输入字段,但不显示键盘

[英]Focus on input field but do not show keyboard

is there any way to set focus on the input field without showing keyboard on a device? 有什么方法可以在不显示键盘的情况下将焦点设置在输入字段上? The code is shared across the website and the mobile device. 该代码在网站和移动设备之间共享。 I just want to acquire situation when on a website I got "focus" on the input element as well as on device but without displaying a keyboard on the device. 我只想了解在网站上我将注意力集中在输入元素以及设备上但没有在设备上显示键盘的情况。 I tried: 我试过了:

document.getElementById("myInput").focus();

but doesn't work. 但不起作用。

Why do you want to focus an input field if you don't want to write in it? 如果不想在输入字段中输入内容,为什么还要关注它? Otherwise you can check with var isMobile = Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent); 否则,您可以使用var isMobile = Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent); if the user agent is mobil before you take the focus. 如果在聚焦之前用户代理是动员的。

It's a normal behavior of device. 这是设备的正常行为。
You can use some cordova plugin (like this cordova-plugin-keyboard ) to hide the keyboard. 您可以使用一些cordova插件(例如此cordova-plugin-keyboard )来隐藏键盘。
Don't forget to check out if the user agent is from a mobile device 不要忘记检查用户代理是否来自移动设备

Anyway, it's the behavior of device, hide the keyboard will make your application act different from the others 无论如何,这是设备的行为,隐藏键盘会使您的应用程序与其他应用程序有所不同

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM