UIWebView iOS document.getElementByID不起作用

vod*_*ang 0 javascript iphone objective-c uiwebview

我有一个非常奇怪的错误UIWebView,我将一个非常简单的html加载到UIWebView:

[self.webview loadHTMLString:@"<html><body><div id='hello'>hello world</div></body></html>" baseURL:nil];

然后拨打以下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')"];
Run Code Online (Sandbox Code Playgroud)

只有第一行,使用getElementsByTagName返回正确的body html,所有其他行只返回一个空字符串@"".我的代码有什么问题?我怎样才能得到div那个有id的hello

vod*_*ang 5

我想出了问题:这是我愚蠢的拼写错误,getElementById而不是getElementByID