简体   繁体   English

当手机页面加载时,如何关注输入字段?

[英]How can I focus on an input field when a phonegap page loads?

I would like to focus on a text input in a PhoneGap application when the page loads. 我想在页面加载时专注于PhoneGap应用程序中的文本输入。 I have tried the MooTools version $('entry').focus(); 我尝试过MooTools版本$('entry').focus(); and document.getElementById('entry').focus() when the DOM is ready. 当DOM准备就绪时, document.getElementById('entry').focus()

This works fine when the HTML page is viewed in a normal web browser, but in the iPhone simulator running PhoneGap, it doesn't work. 当在普通的Web浏览器中查看HTML页面时,这可以正常工作,但在运行PhoneGap的iPhone模拟器中,它不起作用。

Is there a way to focus on a form field for iPhones that forces the virtual keyboard to appear? 有没有办法专注于强制虚拟键盘出现的iPhone的表单字段?

As of iOS 6, the UIWebView class has a property called "keyboardDisplayRequiresUserAction". 从iOS 6开始,UIWebView类具有一个名为“keyboardDisplayRequiresUserAction”的属性。 If you want to programmatically focus text form elements, set this to false via your phonegap config.xml: 如果要以编程方式聚焦文本表单元素,请通过phonegap config.xml将其设置为false:

<preference name="KeyboardDisplayRequiresUserAction" value="false" />

The default value is true. 默认值是true。

More here: http://community.phonegap.com/nitobi/topics/calling_focus 更多信息: http//community.phonegap.com/nitobi/topics/calling_focus

As far as I know, this is an intentional limitation of WebKit on both iPhone and Android; 据我所知,这是iPhone和Android上WebKit的故意限制; only a user touch action can trigger a keyboard. 只有用户触摸动作才能触发键盘。 I'm still trying to concoct a workaround, but I'm not very optimistic. 我仍在尝试制定一个解决方法,但我不是很乐观。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM