使用 Jquery/Javascript (Mobiscroll) 在移动设备上隐藏虚拟键盘
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24908049/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Hide virtual keyboard on mobile with Jquery/Javascript (Mobiscroll)
提问by Dennis Anderson
There are a lot of questions about this. But they all talk about leaving the focus on a field. Here is my problem:
关于这一点有很多问题。但他们都在谈论将重点放在一个领域。这是我的问题:
I have a input type field. When the user clicks on it, it will open my custom mobiscroll feature. and in some cases like by Android 2.* or windows surface tablets it shows the virtual keyboard as well ! How can i code a case that the virtual keyboard will never appear !
我有一个输入类型字段。当用户点击它时,它会打开我的自定义 mobiscroll 功能。在某些情况下,例如 Android 2.* 或 Windows Surface 平板电脑,它还会显示虚拟键盘!我如何编写虚拟键盘永远不会出现的情况!
Who can help me :)
谁能帮我 :)
回答by R3tep
To remove the keyboard you need to lose the focus on the active element. No other solution.
要移除键盘,您需要失去对活动元素的关注。没有其他解决办法。
So display your pop-up and after remove the focus.
所以显示你的弹出窗口,然后移除焦点。
Example:
例子:
function clickInput() {
openPopUp();
document.activeElement.blur(); // lose focus on the active element and hide keyboard
}
UPDATE:
更新:
I do not know "mobiscroll". But to hide the keyboard you need to lose focus on the active element.
我不知道“mobiscroll”。但是要隐藏键盘,您需要失去对活动元素的关注。
document.activeElement && document.activeElement.blur();
// This code remove the keyboard constantly.
回答by Dennis Anderson
Blur was the key for my issue ! Mobiscroll has a method called onBeforeShow that gets called before the mobiscroll appears. In this method I used blur() on the input type i used the mobiscroll on ! My code below:
模糊是我问题的关键!Mobiscroll 有一个名为 onBeforeShow 的方法,该方法在 mobiscroll 出现之前被调用。在这种方法中,我在输入类型上使用了 blur() 我使用了 mobiscroll !我的代码如下:
var options = {
preset: this.preset,
theme: 'wp light',
mode: 'scroller',
display: 'bottom',
timeWheels: "HHii",
dateFormat: "dd-mm-yy",
timeFormat: "HH:ii",
lang: 'nl', // TODO: Deduce from application language.
onBeforeShow: (html, inst) => { this.findControl().blur();}
};
this.findControl().mobiscroll(options);
回答by Dibran
Blur is the key on Android but disabling the parent is the key on WinJS.
模糊是 Android 上的关键,但禁用父级是 WinJS 上的关键。
var control = jQuery("#someControl");
// Disabling the parent prevents the keyboard to popup for WinJS.
control.parent().prop('disabled', true);
var options = {
preset: this.preset,
mode: 'scroller',
display: 'bottom',
timeWheels: "HHii",
dateFormat: "dd-mm-yy",
timeFormat: "HH:ii",
lang: 'nl',
onBeforeShow: function (inst) {
// Blur the control because Android will otherwise show the keyboard.
control.blur();
}
};
control.mobiscroll(options);