如果要在表单中编辑它,可以使用以下方法:
- (void)webViewDidFinishLoad:(UIWebView *)webView {
NSString *evaluate = [NSString stringWithFormat:@"document.form1.main-title.value='%@';", @"New title"];
[webView stringByEvaluatingJavaScriptFromString:evaluate];
}
Run Code Online (Sandbox Code Playgroud)
或者如果不是一种形式,也许这(未经测试):
- (void)webViewDidFinishLoad:(UIWebView *)webView {
NSString *evaluate = [NSString stringWithFormat:@"document.getElementById('main-title').value='%@';", @"New title"];
[webView stringByEvaluatingJavaScriptFromString:evaluate];
}
Run Code Online (Sandbox Code Playgroud)
注意!我认为这是一个你想要改变的可编辑字段.否则你正在谈论解析,这个概念的工作原理如下:
static BOOL firstLoad = YES;
- (void)webViewDidFinishLoad:(UIWebView *)webView {
if (firstLoad) {
firstLoad = NO;
NSString *html = [_webView stringByEvaluatingJavaScriptFromString:@"document.documentElement.outerHTML"];
//Edit html here, by parsing or similar.
[webView loadHTMLString:html baseURL:[[NSBundle mainBundle] resourceURL]];
}
}
Run Code Online (Sandbox Code Playgroud)
您可以在此处阅读有关解析的更多信息:Objective-C html解析器