最近再做一个APP的时候,有一个评论回复的功能,在做APP的时候,直接用手指触发focus事件,来唤醒软键盘的弹出没有问题, 但是现在的功能需要对点击回复进行弹出软键盘来操作,参考过很多都有问题,后来仔细看了下官方的DEMO,发下这个问题是可以被解决掉的。具体方法如下:

<style type="text/css">
.show-input-main{width: 100%; height:40px; border: 1px solid red; position: fixed; left:0px; bottom:0px; z-index: 20;}
.show-input-box{width: 100%; height:40px; padding-right:55px;}
.input-box{width: 100%; height:100%; background:yellow;}
.input-box-btn{width: 55px; height: 100%; background: #007aff; position: absolute; top:0px; right:0px; text-align:center; line-height: 40px; color:#fff; font-size:16px;}
#textarea-input{width: 100%; height:38px; border:1px solid #fff; line-height: 24px; min-height:38px; margin:0px; padding:5px 2px; }
</style>
<div class="mui-input-row">
<button id="showInput">点我回复</button>
</div>
<div class="mui-input-row show-input-main">
<div class="show-input-box">
<div class="input-box">
<textarea id="textarea-input"></textarea>
</div>
<div class="input-box-btn">发送</div>
</div>
</div>

具体JS代码:

mui.init({
swipeBack: true //启用右滑关闭功能
});
//语音识别完成事件
document.getElementById("search").addEventListener('recognized', function(e) {
console.log(e.detail.value);
});
var nativeWebview, imm, InputMethodManager;
var initNativeObjects = function() {
if (mui.os.android) {
var main = plus.android.runtimeMainActivity();
var Context = plus.android.importClass("android.content.Context");
InputMethodManager = plus.android.importClass("android.view.inputmethod.InputMethodManager");
imm = main.getSystemService(Context.INPUT_METHOD_SERVICE);
} else {
nativeWebview = plus.webview.currentWebview().nativeInstanceObject();
}
};
var showSoftInput = function() {
if (mui.os.android) {
imm.toggleSoftInput(0, InputMethodManager.SHOW_FORCED);
} else {
nativeWebview.plusCallMethod({
"setKeyboardDisplayRequiresUserAction": false
});
}
setTimeout(function() {
var inputElem = document.querySelector('input');
inputElem.focus();
inputElem.parentNode.classList.add('mui-active'); //第一个是search,加上激活样式
}, 200);
};
var showInputObj = document.getElementById('showInput');
var clickShowSoftInput = function(){
if (mui.os.android) {
imm.toggleSoftInput(0, InputMethodManager.SHOW_FORCED);
} else {
nativeWebview.plusCallMethod({
"setKeyboardDisplayRequiresUserAction": false
});
}
setTimeout(function() {
var inputElem = document.querySelector('#textarea-input');
inputElem.focus();
inputElem.parentNode.classList.add('mui-active'); //第一个是search,加上激活样式
}, 200);
};
mui.plusReady(function() {
initNativeObjects();
// showSoftInput();
// 监听点击事件
showInputObj.addEventListener('tap',function(){
clickShowSoftInput();
});
});

经测试没有问题。

正常模式使用这个的时候是没有问题的,但如果APP项目采用的是沉浸式模式,使用这个方法,发现弹出的软键盘会遮挡 固定定位的输入框,解决办法是监听软键盘的弹出操作,添加类或样式来进行调整:

var winHeight = $(window).height();
window.onresize = function(){
var thisHeight = $(window).height();
if(winHeight - thisHeight > 50){
console.log('弹出');
}else{
console.log('缩回');
};
};

完美。

最新文章

  1. VM(虚拟机安装win7 提示 :units specified don&#39;t exist, SHSUCDX can&#39;t install)解决方法
  2. VBA控制outlook自动发送邮件(转)
  3. 动态分配的顺序线性表的十五种操作—C语言实现
  4. 使用Qt 开发图形界面的软件
  5. WebApi接口访问频率控制的实现
  6. 单片微机原理P3:80C51外部拓展系统
  7. Linux监控体系
  8. [随笔]利用云虚拟机和学校VPN实现校外访问校内站点(反向代理)
  9. CodeForces 544C (Writing Code)(dp,完全背包)
  10. Delphi备忘录——基本语句
  11. SVD分解 解齐次线性方程组
  12. Atitit 3种类型的公司:运营驱动型;产品驱动型; 技术驱动型。
  13. [Golang] lua战斗验证服务器
  14. centos 关闭selinux
  15. Mac环境下扩容 .vmdk 镜像容量
  16. composer require 指定版本
  17. Linux fdisk普通分区扩容
  18. VBA 操作 VBE
  19. httpd编译安装
  20. 什么是HotSpot

热门文章

  1. C#高级编程四十一天----用户定义的数据类型转换
  2. MDX Cookbook 03 - MDX 查询中负数,零和空值 NULL 的格式化处理
  3. Scala字符串插值
  4. C# System.Collections.Stack
  5. .Net学习资料
  6. Jquery计算时间戳之间的差值,可返回年,月,日,小时等
  7. asp.net core2-&gt;2.1 webapi 进行了重大变更
  8. ASP.NET MVC 自定义处理JSON ActionResult类
  9. 团队工作效率分析工具gitstats
  10. mongodb高级聚合查询(转)