无法模糊ios中的输入
问题描述:
我正在使用Xcode,Cordova和HTML文件构建iPad应用.
I'm building an iPad app using Xcode, Cordova and HTML files.
在iPad上测试HTML时,我无法通过在输入字段外面单击来使输入字段模糊.
In testing the HTML on an iPad, I'm not able to blur my input fields by clicking outside them.
我需要对背景进行编码以使输入模糊吗?
Do I need to code the background to blur the input?
我想要模糊效果,以便隐藏键盘.
I want the blur so I can hide the keyboard.
除非有一种更好的解决方案可以隐藏它,而无需blur().
Unless there's a better solution to hiding it that does not need a blur().
答
我发现了两个代码段,当单击输入之外的任何地方或按Return键时,这些代码段组合在一起可触发输入模糊.
I found two code snippets that combine to trigger blur on inputs when clicking anywhere outside the input, or when pressing the Return key.
function isTextInput(node) {
return ['INPUT'].indexOf(node.nodeName) !== -1;
}
document.addEventListener('touchstart', function(e) {
if (!isTextInput(e.target) && isTextInput(document.activeElement)) {
document.activeElement.blur();
}
}, false);
$('input').keyup(function(event) {
if (event.which === 13) {
$(this).blur();
}
});