gpt4 book ai didi

javascript - 如何使用 JavaScript 隐藏 Android 键盘?

转载 作者:IT王子 更新时间:2023-10-28 23:49:37 24 4
gpt4 key购买 nike

我想在 JavaScript 中隐藏 Android 虚拟键盘。有人建议做this :

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

但如果键盘已经可见,这将不起作用。这是可以做到的吗?

最佳答案

我找到了一个更简单的解决方案,它既不需要添加元素,也不需要特殊类。在那里找到它:http://www.sencha.com/forum/archive/index.php/t-141560.html

并将代码转换为jquery:

function hideKeyboard(element) {
element.attr('readonly', 'readonly'); // Force keyboard to hide on input field.
element.attr('disabled', 'true'); // Force keyboard to hide on textarea field.
setTimeout(function() {
element.blur(); //actually close the keyboard
// Remove readonly attribute after keyboard is hidden.
element.removeAttr('readonly');
element.removeAttr('disabled');
}, 100);
}

您可以通过将打开键盘的输入传递给该函数来调用该函数,或者仅传递 $('input') 也应该可以工作。

关于javascript - 如何使用 JavaScript 隐藏 Android 键盘?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8335834/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com