Android平台
[JavaScript] 纯文本查看 复制代码 <!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Native.js</title>
<script type="text/javascript">
// H5 plus事件处理
function plusReady(){
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.addEventListener("plusready",plusReady,false);
</script>
</head>
<body>
<button>Close</button><br/>
<input type="text" autofocus="autofocus"/>
<br/>
打开页面后编辑框自动获取焦点并显示软键盘
</body>
</html>
iOS平台
[JavaScript] 纯文本查看 复制代码 <!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Native.js</title>
<script type="text/javascript">
// H5 plus事件处理
function plusReady(){
var webView = plus.webview.currentWebview().nativeInstanceObject();
webView.plusCallMethod({"setKeyboardDisplayRequiresUserAction":false});
document.getElementById("testautofocus").focus();
}
document.addEventListener("plusready",plusReady,false);
</script>
</head>
<body>
<button>Close</button><br/>
<input type="text" id="testautofocus"/>
<br/>
打开页面后编辑框自动获取焦点并显示软键盘
</body>
</html>
|