jquery - iPad HTML 焦点

标签 jquery html ipad

我在 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/

相关文章:

iphone - 如何在 ios 中为 ipad 构建 html5 应用程序?

iphone - 在我的头文件中声明方法

iphone - NSMutableURLRequest 在大约 15 秒后超时。超时设置为 240 秒

javascript - 如何使用 javascript 在没有 ActiveXObject 的情况下将数据写入文本文件?

javascript - 第二次单击后无法动态设置单选按钮值

javascript - 放大的背景图像

javascript - 如何显示通过 div 中的 html 输入选择的照片?

javascript - 停止从方法调用的 ajax 请求 (ES6)

php - 返回 JSON 格式的所有数据的单个 API 调用会比返回部分的多个 API 调用更快吗?

javascript - jquery .not 阻止 nav 隐藏