我需要从 UIWebView 中选择一些文本。我提到了这个答案Getting selected elements programmatically from uiwebview? 但是当我使用点击它选择文本时。但它也显示所有 HTML 字符Selected Name: 1 Name of instrument
-(void)singleTap:(UIGestureRecognizer *)gestureRecognizer
{
NSLog(@"single tap");
CGPoint touchPoint = [gestureRecognizer locationInView:wbCont];
//NSString *js = [NSString stringWithFormat:@"document.elementFromPoint(%f, %f).toString()", touchPoint.x, touchPoint.y];
NSString *js = [NSString stringWithFormat:@"document.elementFromPoint(%f, %f).innerHTML", touchPoint.x, touchPoint.y];
NSString * tagName = [wbCont stringByEvaluatingJavaScriptFromString:js];
NSLog(@"Selected Name: %@",tagName);
}