我在 iPad 上聚焦文本字段时遇到问题。我在哪里使用:
$(document).bind("click",function(event) {
alert('click');
focusTextArea();
});
焦点设置到文本区域,并出现一个键盘。但是,当使用 touchend 调用时,focusTextArea
不会被调用,键盘也不可见。我的 focusTextArea
函数是:
function focusTextArea() {
$('#textArea').focus();
}
有谁知道为什么会发生这种情况,以及我如何才能让它发挥作用?
TIA,
亚当
最佳答案
不幸的是,iPad 无法进行对焦。将焦点置于所需字段的唯一方式是当用户“点击”所需字段时。
2015-01-08 更新:
如 this answer 中所述通过 Matt :
... iOS will only allow focus to be triggered on other elements, from within a function, if the first function in the call stack was triggered by a non-programmatic event. In your case, the call to setTimeout starts a new call stack, and the security mechanism kicks in to prevent you from setting focus on the input.
关于jquery - iPad HTML 焦点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5978470/