简体   繁体   中英

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.

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 ?

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">

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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