如何为 iPhone UIWebView 中加载的页面设置默认(提交)按钮(stringByEvaluatingJavaScriptFromString?)

发布于 2024-08-09 01:55:04 字数 198 浏览 2 评论 0原文

我正在使用 UIWebView 在我的 iPhone 应用程序中加载 HTML 表单。

该表单具有三个提交按钮(在 iPhone 键盘上选择“执行”将选择第一个提交按钮)。

我假设我可以设置一个不同的“默认”提交按钮,并将 JavaScript 注入到下载的表单中,但我不太了解 JavaScript。

有谁知道如何更改默认提交按钮?

I'm using a UIWebView to load an HTML form in my iPhone app.

The form has three submit buttons (and selecting "Go" on the iPhone keypad selects the first submit button).

I'm assuming that I can set a different "default" submit button with Javascript injection into the downloaded form, but I don't know Javascript well.

Does anyone know how to change the default submit button ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

血之狂魔 2024-08-16 01:55:04

我刚刚遇到这个问题,现在正在使用以下技术;

首先,大多数浏览器使用表单上的“第一个”提交按钮,并且由于我希望默认操作为“发送”,因此我在标签后立即添加以下内容:

<input type="submit" name="Send" value="hidden for default enter action" style="display:none">

它不会显示,但在以下情况下仍用作提交按钮:按回车键 - 除了在 iPhone 上出于某种原因 - 可能 webkit 决定应该忽略隐藏的提交按钮,因为它是隐藏的。对于这些浏览器,我只需执行以下操作;

<input type="text" name="test" value="something"
    onfocus="this.form.submitBtn.name='Send';"
    onblur="this.form.submitBtn.name='Search';"
    >
<input type="submit" id="submitBtn" name="Search" value="Search">

即当用户单击输入字段时,它将默认按钮的名称更改为我想要的操作;当我单击该字段之外时,它会返回到原始状态。

I've just hit this problem, and am now using the following pair of techniques;

Firstly, most browsers use the "first" submit button found on the form, and as I want my default action to be "Send", I add the following immediately after the tag:

<input type="submit" name="Send" value="hidden for default enter action" style="display:none">

It's not displayed, but still used as a submit button when hitting enter - except on the iPhone for some reason - possibly webkit decides that the hidden submit button should be ignored, as it's hidden. For these browsers, I simply do the following;

<input type="text" name="test" value="something"
    onfocus="this.form.submitBtn.name='Send';"
    onblur="this.form.submitBtn.name='Search';"
    >
<input type="submit" id="submitBtn" name="Search" value="Search">

i.e. when the users clicks on the input field, it changes the name of the default button to the action that I want; when I click out of the field, it returns to the original.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文