Set text for a textfield in UIWebView

2019-01-22 15:01发布

I have a UIWebView and I want to set one of it's text field to certain text. Is that even possible? If so, how can I do that? Thanks

1条回答
对你真心纯属浪费
2楼-- · 2019-01-22 15:49

Yes you can set the text for a textfield in the UIWebView using javascript

As an example if you have a textfield in this form

<input id="textFieldID" type="text" value="TextValue"/>

Setting value:

[theWebView stringByEvaluatingJavaScriptFromString:@"document.getElementById('textFieldID').value = 'Hello World'"]

Getting value:

NSString* value = [theWebView stringByEvaluatingJavaScriptFromString:@"document.getElementById('textFieldID').value"];
查看更多
登录 后发表回答