先来体验下这个神奇的功能(兼容iOS和Android):
 
此功能需要在模块权限中配置Native.js
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() {  
       //此处可写具体逻辑设置获取焦点的input  
       var inputElem = document.querySelector('input');  
              inputElem.focus();   
    }, 200);  
};  
mui.plusReady(function() {  
    initNativeObjects();  
    showSoftInput();  
});补充更新:
调用plus.webview.create()创建新的webview,会导致当前webview失去焦点,因此可能出现键盘闪一下又消失的情况。
解决方案:将创建webview的代码放到显示键盘之前(initNativeObjects方法之前)。
另外,为了强制当前webview获得焦点,可像如下方式修改showSoftInput方法:
var showSoftInput = function() {  
    var nativeWebview = plus.webview.currentWebview().nativeInstanceObject();  
    if (mui.os.android) {  
        //强制当前webview获得焦点  
        plus.android.importClass(nativeWebview);  
        nativeWebview.requestFocus();  
        imm.toggleSoftInput(0, InputMethodManager.SHOW_FORCED);  
    } else {  
        nativeWebview.plusCallMethod({  
            "setKeyboardDisplayRequiresUserAction": false  
        });  
    }  
    setTimeout(function() {  
       //此处可写具体逻辑设置获取焦点的input  
       var inputElem = document.querySelector('input');  
              inputElem.focus();   
    }, 200);  
}; 
             
             
             
			 
                                                                            



















 
                                                                     
                                                                     
                                                                     
                                                                     
                                                                     
                                                                     
                                                                    