Hide virtual keyboard on mobile with Jquery/Javascript (Mobiscroll)

江枫思渺然 提交于 2021-02-07 09:25:02

问题


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 !

Who can help me :)


回答1:


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.

document.activeElement && document.activeElement.blur();
// This code remove the keyboard constantly.



回答2:


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:

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);



回答3:


Blur is the key on Android but disabling the parent is the key on 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);


来源:https://stackoverflow.com/questions/24908049/hide-virtual-keyboard-on-mobile-with-jquery-javascript-mobiscroll

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!