zoukankan      html  css  js  c++  java
  • 打开页面默认弹出软键盘,同时兼容iOS和Android

    // 示例1
    open_soft_keyboard({
        input: "#username"
    });
    // 示例2
    open_soft_keyboard({
        input: 'input[value=""]'
    });
    
    
    /**
     * 默认打开软键盘
     * @param options{
     *   input: '#nickname' // 容器节点
     * }
     * @author 蔡繁荣
     * @version 1.0.3 build 20151226
     */
    function open_soft_keyboard(options){
        if(plus.os.name == 'iOS'){
            setTimeout(function(){
                var wv_current = plus.webview.currentWebview().nativeInstanceObject();
                wv_current.plusCallMethod({"setKeyboardDisplayRequiresUserAction":false});
                document.querySelector(options['input']).focus();
            }, 330);
        }else{
            // 因为安卓autofocus只有4.0版本以上才支持,所以这里使用native.js来强制弹出
            setTimeout(function(){
                // 在执行的时候需要让当前webview获取焦点
                var wv_current = plus.android.currentWebview();
                plus.android.importClass(wv_current);
                wv_current.requestFocus();
    
                var Context = plus.android.importClass("android.content.Context");
                var InputMethodManager = plus.android.importClass("android.view.inputmethod.InputMethodManager");
                var main = plus.android.runtimeMainActivity();
                var imm = main.getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.toggleSoftInput(0,InputMethodManager.SHOW_FORCED);
                document.querySelector(options['input']).focus();
            }, 330);
        }
    }
    

      

  • 相关阅读:
    php中file_get_contents的图片乱码
    Lsh and Rsh (左移和右移)
    |=的含义
    Intercultural Communication Drama
    VS代码块快速折叠快捷键
    C++sqrt()函数与sqrtf()函数的区别
    C++中union和struct之间的区别
    泛型编程
    生成百度网盘目录文件
    字符串前L的含义
  • 原文地址:https://www.cnblogs.com/chenchenphp/p/6274650.html
Copyright © 2011-2022 走看看