禁用 Android 键盘的“Go” WebView 文本输入按钮
我正在开发一个 Android 应用程序,它使用指向基于 jQueryMobile 的站点的 WebView。通常,禁用软键盘上的“Go”按钮就像将 android:imeOptions="actionDone"
添加到控件的 XML 标记一样简单。然而,对于 WebViews 来说,这并不能解决问题。
如何禁用“Go”按钮自动执行表单提交,或者简单地将其替换为“Done”按钮,就像 EditText 的 android:imeOptions="actionDone"
一样?
I am developing an Android application that uses a WebView pointed at a jQueryMobile-based site. Normally, disabling the 'Go' button on the soft keyboard is as simple as adding android:imeOptions="actionDone"
to the control's XML tag. In the case of WebViews however, this doesn't do the trick.
How can I disable the 'Go' button from automatically doing a form submission, or alternatively to simply replace it with the 'Done' button, like android:imeOptions="actionDone"
would for an EditText?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以通过放置表单的
onsubmit
事件来停止提交表单。You may stop submitting form by putting the
onsubmit
event of the form.这是使用维卡斯提到的方法的更详细的答案。
由于问题在于表单正在提交,因此您可以向运行 JavaScript 的表单元素添加 onSubmit 属性,以确定是否应提交表单。
下面是您不想提交的表单:
并包含此返回 false 的脚本,这会阻止您的表单提交。
现在,当您在文本输入字段中输入文本后按“Go”时,键盘将简单地折叠而不提交表单。
这也可以用于检查表单中的错误。请参阅下面的网页:
http://www.htmlcodetutorial.com/forms/_FORM_onSubmit.html
Here's a more detailed answer that uses the method alluded to by Vikas.
Since the problem is that your form is submitting, you can add an onSubmit attribute to your form element that runs JavaScript to determine if your form should be submitted.
Below is the form that you don't want to submit:
And include this script that returns false which keeps your form from submitting.
Now, when you press Go after entering text into your text input field, the keyboard will simply collapse without submitting the form.
This could also be used to check for errors in your form. See the webpage below:
http://www.htmlcodetutorial.com/forms/_FORM_onSubmit.html