简体   繁体   中英

hide keyboard on ios device when focus in input

当一些插件(或其他代码)使用纯javascript(或jquery库)设置焦点到html页面上的输入元素时,我想在ipad设备上隐藏虚拟键盘

If you need a pure solution, use this line :

document.activeElement.blur();

This line removes the focus on the active element and hiding the keyboard.


Reference

You would have to blur it again but the keyboard might flash.

$('input').on('focus', function() { $(this).blur(); });

Or, depending on if you have dynamically created input elements.

$('#wrapper').on('focus', 'input', function() { $(this).blur(); });

Typescript version requires to fire blur() on HTMLElement . Like this:

let myElement: HTMLElement;
myElement = <HTMLElement>document.activeElement;
myElement.blur()

有时,它需要等待一段时间。

setTimeout(function() { document.activeElement.blur(); }, 100);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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