在UIWebView中设置文本字段的文本

Dex*_*ter 11 cocoa-touch objective-c uiwebview uiview ios

我有一个UIWebView,我想将其中一个文本字段设置为某些文本.这甚至可能吗?如果是这样,我该怎么做?谢谢

Cyp*_*ian 22

是的,您可以使用javascript在UIWebView中设置文本字段的文本

例如,如果您有此表单中的文本字段

<input id="textFieldID" type="text" value="TextValue"/>
Run Code Online (Sandbox Code Playgroud)

设定值:

[theWebView stringByEvaluatingJavaScriptFromString:@"document.getElementById('textFieldID').value = 'Hello World'"]
Run Code Online (Sandbox Code Playgroud)

获得价值:

NSString* value = [theWebView stringByEvaluatingJavaScriptFromString:@"document.getElementById('textFieldID').value"];
Run Code Online (Sandbox Code Playgroud)