问题
I'm building an iPad app using Xcode, Cordova and HTML files.
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.
Unless there's a better solution to hiding it that does not need a blur().
回答1:
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();
}
});
来源:https://stackoverflow.com/questions/45487878/cant-blur-input-in-ios