【发布时间】:2015-12-01 03:37:31
【问题描述】:
在 WkWebView 向包含的网页发送 javascript 函数调用后,我正试图让 WkWebView 打开一个键盘以编程方式输入电话文本。
在此调用激活某个输入(id:activeElementToShowKeyboard)后,出于效率原因,我希望键盘显示先前的电话输入(id:numberInput)。
元素永远不会获得焦点并打开键盘。
我理解为什么当元素请求焦点时键盘不会自动打开,但我想一定有办法做到这一点。
我试过了(没有运气): 点击(); 重点(); 点击()。焦点(); 快速点击 j手势
这是一个将在本地运行的示例。在 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 = $(".target");
var newActiveElement = divs.eq((divs.index($selected) + 1) % divs.length).addClass("active");
if ($(newActiveElement).is("#activeElementToShowKeyboard")) {
//alert("Should bring up keyboard!");
$("#numberInput").focus();
}
}
</script>
</body>
</html>
我的目标是所有 iOS 设备,主要是 iPod touch(第 5 代/第 6 代)或 iPhone 6。我正在 iOS 8.4 上进行测试
有人有什么想法吗?
【问题讨论】:
标签: javascript jquery ios keyboard wkwebview