我一直在寻找如何通过 Javascript 触发 android 键盘。
我找到了一些答案,但似乎都不起作用。
这里有一个解决方案: Showing Android's soft keyboard when a field is .focus()'d using javascript
在上面的例子中有一个我没有的按钮,但我需要它吗?
我正在通过 touch-layer.js 使用“点击”和“滑动”事件,这似乎禁用了点击事件以支持点击。 ( https://github.com/cubiq/touch-layer )
下面是我试过的代码,警报触发,焦点发生但键盘不显示。
gt("#txtEmail").on("tap", function() {
alert('tap');
$(this)[0].el[0].focus();
$("#txtEmail").trigger('click');
});
谢谢。
编辑 1:第二次尝试无效,即使这看起来更符合示例。
gt("#txtEmail").on("tap", function() {
alert('trigger');
$("#txtEmail").trigger('click');
});
$("#txtEmail").on("click", function() {
alert('recieved');
$(this).focus();
});
最佳答案
除了 Jack He 的建议,请查看 ionic-plugin-keyboard .许多人更积极地维护和使用这个。
在我的例子中,我只是将 focus
事件绑定(bind)到一个手动显示键盘的处理函数。
$(".my-input").on("focus", function(e) {
...
cordova.plugins.Keyboard.show();
...
});
关于javascript - Phonegap Android 在输入焦点 Javascript 上显示键盘,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27346790/