Javascript 在UIWebView中滚动

Javascript 在UIWebView中滚动,javascript,iphone,html,objective-c,ios,Javascript,Iphone,Html,Objective C,Ios,我想知道是否可以在UIWebView中滚动到给定的id 我知道我可以使用以下工具滚动到给定(x,y)点: [self.myWebView.scrollView setContentOffset:CGPointMake(x, y) animated:YES]; 我正在本地加载html文件,因此我发现html文件中的元素可以“标记”如下: <element id="myID"> 但它不起作用。我做错了什么 提前感谢。只需像这样导航到id: [self.myWebView stri

我想知道是否可以在UIWebView中滚动到给定的id

我知道我可以使用以下工具滚动到给定(x,y)点:

 [self.myWebView.scrollView setContentOffset:CGPointMake(x, y) animated:YES];
我正在本地加载html文件,因此我发现html文件中的元素可以“标记”如下:

 <element id="myID">
但它不起作用。我做错了什么


提前感谢。

只需像这样导航到id:

[self.myWebView stringByEvaluatingJavaScriptFromString: @"window.location.hash='#myID'"];
[self.myWebView stringByEvaluatingJavaScriptFromString: @"window.location.hash='#myID'"];