can't blur input in ios

早过忘川 提交于 2019-12-12 04:37:39

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!