我在视图控制器中有以下代码."pageDisplay"是一个UIWebView.当我在模拟器中运行应用程序时,HTML页面出现在JS运行之前.ID为"myHeader"的元素(标记)保持不变.
-(void) loadPageToView:(int)pageNumber{ NSString *path = [[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"%d",pageNumber]ofType:@"html"]; NSURL *url = [NSURL fileURLWithPath:path]; NSURLRequest *request = [NSURLRequest requestWithURL:url]; [pageDisplay loadRequest:request]; [self doJavaScript]; } -(void) doJavaScript{ [pageDisplay stringByEvaluatingJavaScriptFromString:@"document.getElementById('myHeader').innerHTML = \"FOO\";"]; }
Benedict Coh.. 6
你打电话doJavaScript
太早了.您需要等到页面加载完毕.调查Web视图委托方法- (void)webViewDidFinishLoad:(UIWebView *)webView
.
你打电话doJavaScript
太早了.您需要等到页面加载完毕.调查Web视图委托方法- (void)webViewDidFinishLoad:(UIWebView *)webView
.