我有一个问题,关注iPad上的文本字段.我在哪里使用:
$(document).bind("click",function(event) { alert('click'); focusTextArea(); });
焦点设置为文本区域,并出现键盘.但是,当使用touchend调用时,不会调用focusTextArea并且键盘不可见.我的focusTextArea函数是:
function focusTextArea() { $('#textArea').focus(); }
有谁知道为什么会发生这种情况,以及我怎么能让它发挥作用?
TIA,
亚当
解决方法
不幸的是,iPad无法实现对焦.将焦点放在所需字段中的唯一方法是用户“点击”所需字段.
更新2015-01-08:
如this answer by 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.