Set text for a textfield in UIWebView

后端 未结 2 1893
面向向阳花
面向向阳花 2020-12-14 11:10

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

2条回答
  •  旧巷少年郎
    2020-12-14 11: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

    
    

    Setting value:

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

    Getting value:

    NSString* value = [theWebView stringByEvaluatingJavaScriptFromString:@"document.getElementById('textFieldID').value"];
    

提交回复
热议问题