在WkWebView向所包含的网页发送javascript函数调用后,我试图以编程方式使WkWebView打开用于输入电话文本的键盘。
在此调用激活了某个输入(id:activeElementToShowKeyboard)之后,出于效率考虑,我希望键盘显示先前的tel输入(id:numberInput)。
该元素永远不会获得焦点并打开键盘。
我知道为什么当元素请求焦点时键盘不会自动打开,但是我想必须有一种方法可以做到这一点。
我已经尝试过(没有运气):click(); 焦点(); click()。focus(); FastClick jGestures
这是一个将在本地运行的示例。在chrome的开发人员控制台中,您可以输入FunctionCalledByWkWebView(“ text”); 并且可以使用,但在iOS上,键盘永远不会在注释掉的警报下的行中打开。
<!DOCTYPE html>
<html lang="en">
<head>
<title>Test</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1, user-scalable=0">
<meta name="format-detection" content="telephone=no" />
<script src="https://code.jquery.com/jquery-1.11.3.js"></script>
</head>
<body>
<div>
<input type="text" class="active target" />
<input type="text" class="target" />
<input type="tel" id="numberInput" />
<input type="text" class="target" id="activeElementToShowKeyboard" />
</div>
<style type="text/css">
.active {
background-color: red;
}
</style>
<script type="text/javascript">
$(".target").focusin(function() {
$(".active").removeClass("active");
$(this).addClass("active");
});
function FunctionCalledByWkWebView(someText) {
var $selected = $(".active").removeClass("active");
$selected.val(someText);
var divs …Run Code Online (Sandbox Code Playgroud)