简体   繁体   English

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

[英]How to set the default (submit) button for a page loaded in an iPhone UIWebView (stringByEvaluatingJavaScriptFromString?)

I'm using a UIWebView to load an HTML form in my iPhone app. 我正在使用UIWebView在iPhone应用程序中加载HTML表单。

The form has three submit buttons (and selecting "Go" on the iPhone keypad selects the first submit button). 该表单具有三个提交按钮(并且在iPhone键盘上选择“执行”将选择第一个提交按钮)。

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. 我假设我可以在将Javascript注入下载的表单中设置一个不同的“默认”提交按钮,但是我不太了解Javascript。

Does anyone know how to change the default submit button ? 有谁知道如何更改默认的提交按钮?

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. 它不会显示,但是在按Enter键时仍用作提交按钮(由于某些原因,在iPhone上除外)-可能是Webkit决定应该忽略隐藏的提交按钮,因为它是隐藏的。 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">

ie 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. 当我单击该字段之外时,它将恢复为原始状态。

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

相关问题 UIWebView stringByEvaluatingJavaScriptFromString - UIWebView stringByEvaluatingJavaScriptFromString 如何将提交按钮设置为表单的默认按钮 - How to set submit button as default button for form 页面加载后如何禁用提交按钮10秒钟 - how to disable a submit button for 10 seconds after the page is loaded UIWebView stringByEvaluatingJavaScriptFromString不起作用 - UIWebView stringByEvaluatingJavaScriptFromString not working UIWebView stringByEvaluatingJavaScriptFromString遇到了麻烦 - UIWebView stringByEvaluatingJavaScriptFromString woes UIWebView stringByEvaluatingJavaScriptFromString调试 - UIWebView stringByEvaluatingJavaScriptFromString debugging 如何将JavaScript注入到UIWebView中加载的网页中? - How to inject javascript into a web page loaded in UIWebView? 使用UIWebView-stringByEvaluatingJavaScriptFromString执行的脚本可以使用多长时间? - How long the script executed using UIWebView-stringByEvaluatingJavaScriptFromString will be available? 如何在UIWebView中使用stringByEvaluatingJavaScriptFromString而不是Swift中的performSelectorOnMainThread显示JavaScript警报对话框? - How to display a JavaScript alert dialog in UIWebView using stringByEvaluatingJavaScriptFromString but not performSelectorOnMainThread in Swift? 如何在弹出窗口中的提交按钮上设置默认焦点 window - how to set default focus on the submit button in a popup window
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM