How can I hide the Android keyboard using JavaScript?

CommunityYoh Suzuki提出了一个问题:How can I hide the Android keyboard using JavaScript?,或许与您遇到的问题类似。

回答者rdougan给出了该问题的处理方式:

What you need to do is create a new input field, append it to the body, focus it and the hide it using display:none. You will need to enclose these inside some setTimeouts unfortunately to make this work.

var field = document.createElement('input');
field.setAttribute('type', 'text');
document.body.appendChild(field);

setTimeout(function() {
    field.focus();
    setTimeout(function() {
        field.setAttribute('style', 'display:none;');
    }, 50);
}, 50);

希望本文对你有帮助,欢迎支持JavaScript中文网