当 PhoneGap 页面加载时,如何聚焦于输入字段?
我想重点关注页面加载时 PhoneGap 应用程序中的文本输入。当 DOM 准备好时,我尝试了 MooTools 版本 $('entry').focus();
和 document.getElementById('entry').focus()
。
当在普通的 Web 浏览器中查看 HTML 页面时,这可以正常工作,但在运行 PhoneGap 的 iPhone 模拟器中,它不起作用。
有没有办法专注于 iPhone 的表单字段,强制虚拟键盘出现?
I would like to focus on a text input in a PhoneGap application when the page loads. I have tried the MooTools version $('entry').focus();
and document.getElementById('entry').focus()
when the DOM is ready.
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.
Is there a way to focus on a form field for iPhones that forces the virtual keyboard to appear?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
从 iOS 6 开始,UIWebView 类有一个名为“keyboardDisplayRequiresUserAction”的属性。如果您想以编程方式聚焦文本表单元素,请通过phonegap config.xml 将其设置为 false:
默认值为 true。
更多信息请参见:http://community.phonegap.com/nitobi/topics/calling_focus
As of iOS 6, the UIWebView class has a property called "keyboardDisplayRequiresUserAction". If you want to programmatically focus text form elements, set this to false via your phonegap config.xml:
The default value is true.
More here: http://community.phonegap.com/nitobi/topics/calling_focus
据我所知,这是 WebKit 在 iPhone 和 Android 上有意的限制;只有用户触摸动作才能触发键盘。我仍在尝试制定解决方法,但我不太乐观。
As far as I know, this is an intentional limitation of WebKit on both iPhone and Android; only a user touch action can trigger a keyboard. I'm still trying to concoct a workaround, but I'm not very optimistic.