zoukankan      html  css  js  c++  java
  • MUI

    ##打开页面默认弹出键盘及返回关闭键盘 http://www.cnblogs.com/phillyx/

    (function(keyboard) {
    	var openSoftKeyboard = function() {
    		if (mui.os.ios) {
    			var webView = plus.webview.currentWebview().nativeInstanceObject();
    			webView.plusCallMethod({
    				"setKeyboardDisplayRequiresUserAction": false
    			});
    		} else {
    			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);
    		}
    	};
    	var autoFocus = function(obj) {
    		if (mui.os.ios) {
    			setTimeout(function() {
    				openSoftKeyboard();
    				obj.focus();
    				if (obj.tagName.toLowerCase() == 'textarea') {
    					moveEnd(obj);
    				}
    			}, 300);
    		} else {
    			//安卓的获取不到焦点,暂时不自动弹出
    		}
    	};
    	keyboard.autoFocus = autoFocus;
    	/**
    	 * 预加载页面返回时为隐藏,不会自动关闭输入法,可以通过blur来关闭
    	 * @param {Object} isRemoveValue
    	 */
    	function blur(isRemoveValue) {
    		var ac = document.activeElement;
    		ac.blur();
    		if (isRemoveValue && ac.value) {
    			ac.value = '';
    		}
    	};
    	keyboard.blur = blur;
    	/**
    	 * @description ios下textarea.onfocus 时,默认在字首,添加该方法移动到尾部
    	 * @param {Object} obj
    	 */
    
    	function moveEnd(obj) {
    		var len = obj.value.length;
    		if (document.selection) {
    			var sel = obj.createTextRange();
    			sel.moveStart('character', len);
    			sel.collapse();
    			sel.select();
    		} else if (typeof obj.selectionStart == 'number' && typeof obj.selectionEnd == 'number') {
    			obj.selectionStart = obj.selectionEnd = len;
    		}
    	};
    	//			mui.plusReady(function() {
    	//				if (mui.os.android) {
    	//					Array.prototype.forEach.call(document.querySelectorAll(".mui-input-group input[type='text']"), function(ip) {
    	//						ip.setAttribute('autofocus', 'autofocus');
    	//					});
    	//				}
    	//			});
    }(window.mykeyboard = {}));
    
  • 相关阅读:
    【sqlserver】sqlserver表中导入大批量数据
    java中json结果检查
    spoj375Query on a tree树链剖分
    Hdu4737 ( A Bit Fun ) 线段树
    CodeForces 274E. Riding in a LiftDp
    D. Red-Green Towers Dp
    Hdu5067旅行商
    Hdu5068线段树
    uva11992线段树
    uva1400线段树
  • 原文地址:https://www.cnblogs.com/phillyx/p/4745963.html
Copyright © 2011-2022 走看看