iPad HTML 焦点 [英] iPad HTML Focus

查看:14
本文介绍了iPad HTML 焦点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 iPad 上聚焦文本字段时遇到问题.我在哪里使用:

I have an issue with focusing a text field on the iPad. Where I use:

$(document).bind("click",function(event) {
    alert('click');
    focusTextArea();
});

焦点设置在文本区域,并出现一个键盘.但是,当使用 touchend 调用时,不会调用 focusTextArea 并且键盘不可见.我的 focusTextArea 函数是:

The focus is set to the text area, and a keyboard appears. However when called with touchend, focusTextArea is not called and the keyboard is not made visible. My focusTextArea function is:

function focusTextArea() {
    $('#textArea').focus();
}

有谁知道为什么会发生这种情况,以及我如何才能让它发挥作用?

Does anybody know why this occurs, and how I might be able to get this to work?

TIA,

亚当

推荐答案

遗憾的是,无法使用 iPad 进行对焦.将焦点置于所需字段的唯一方法是当用户点击"所需字段时.

Unfortunately, focusing is not possible with the iPad. The only way the focus will be placed in the desired field is when the user 'clicks' on the desired field.

2015-01-08 更新:

此答案中所述,马特:

...iOS 将只允许在其他元素上触发焦点,从在函数内,如果调用堆栈中的第一个函数是由非程序性事件触发.在你的情况下,调用setTimeout 启动新的调用栈,安全机制启动in 以防止您将焦点设置在输入上.

... 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.

这篇关于iPad HTML 焦点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆