我有一个非常奇怪的错误UIWebView
,我将一个非常简单的html加载到UIWebView
:
[self.webview loadHTMLString:@"
然后拨打以下4行:
NSString *body = [self.webview stringByEvaluatingJavaScriptFromString: @"document.getElementsByTagName('body')[0].outerHTML"]; NSString *helloValue = [self.webview stringByEvaluatingJavaScriptFromString: @"document.getElementByID('hello').value"]; NSString *helloOuter = [self.webview stringByEvaluatingJavaScriptFromString: @"document.getElementByID('hello').outerHTML"]; NSString *helloInner = [self.webview stringByEvaluatingJavaScriptFromString: @"document.getElementByID('hello').innerHTML"]; NSString *helloElement = [self.webview stringByEvaluatingJavaScriptFromString: @"document.getElementByID('hello')"];
只有第一行,使用getElementsByTagName返回正确的body html,所有其他行只返回一个空字符串@"".我的代码有什么问题?我怎样才能得到div
那个有id的hello
我想出了问题:这是我愚蠢的拼写错误,getElementById
而不是getElementByID