当输入失去焦点时,如何防止Cordova隐藏键盘 [英] How to prevent cordova to hide the keyboard when the input loses the focus

查看:203
本文介绍了当输入失去焦点时,如何防止Cordova隐藏键盘的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用phonegap制作一个用于android的聊天应用程序,但是我遇到了问题.

I'm making a chat application for android with phonegap but i'm facing a problem.

我有一个文本区域(用户可以在其中写消息)和一个用于发送消息的按钮.

I have a text area field (where the users can write their messages) and a button to send the messages.

当用户单击文本区域时,键盘会出现.但是,当用户单击按钮发送消息时,文本区域字段将失去焦点,键盘消失.我想保持键盘显示状态,并将焦点返回到文本区域.

When the user clicks on the text area, the keyboard comes up. However, when the user clicks the button to send the message, the text area field loses the focus and the keyboard disappears. I'd like to keep to keyboard displayed and give back the focus to the text area.

我尝试用选择键盘

$('#text-area).focus()

但是没有成功.

我还将此行添加到了config.xml中.

I have also added this line to my config.xml.

<preference name="KeyboardDisplayRequiresUserAction" value="false"/>

我尝试使用插件 https://github.com/driftyco/ionic-插件键盘.当键盘要隐藏时,它会触发一个事件,但是我唯一能做的就是用

I've tried to use the plugin https://github.com/driftyco/ionic-plugins-keyboard. When the keyboard is going to hide, it fires an event but the only thing I can do is to open it again with

cordova.plugins.Keyboard.show();

问题是键盘隐藏/显示并且动画仍被触发.

The problem is that the keyboard hide/show and the animation is still triggered.

有什么建议吗?

推荐答案

我这样做是这样的:

<textarea id="NewTextBox" ng-model="newMsgModel.text" ng-click="add()"></textarea>

和angularJS中的

and in angularJS:

$scope.add = function () {
    /** add message to db ...*/ 

    /** keep Keyboard Open*/
    $('#NewTextBox').focus();
};

这篇关于当输入失去焦点时,如何防止Cordova隐藏键盘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆