iPad的HTML焦点 [英] iPad HTML Focus

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

问题描述

我在iPad上关注文本字段时遇到了问题。我在哪里使用:

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

将焦点设置到文本区域,并出现键盘。但是,使用touchend调用时, focusTextArea 不会被调用,并且键盘不可见。 focusTextArea 函数是: b $('#textArea')。focus();
}

有人知道为什么会出现这种情况,我怎么能够得到这个工作?

TIA,

Adam

解决方案

遗憾的是,使用iPad无法实现专注。将焦点放在所需字段的唯一方法是当用户点击所需字段。



更新2015-01-08:



正如此答案 马特


...
如果调用堆栈中的第一个函数是由非编程事件触发的
,则iOS仅允许在函数内的
的其他元素上触发焦点。在你的情况下,对
setTimeout的调用会启动一个新的调用堆栈,并且安全机制会触发
以阻止您将注意力集中在输入上。



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

$(document).bind("click",function(event) {
    alert('click');
    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,

Adam

解决方案

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.

Update 2015-01-08:

As explained in 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.

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

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