2014-07-27 31 views
2

我在我的iOS應用中加載了一個webview窗體,我想自動對焦窗體上的文本框。我試過UIWebview中的自動對焦文本字段

NSString *focus = [NSString stringWithFormat:@"document.getElementsByName('j_captcha')[0].focus()"]; 
[self.webView stringByEvaluatingJavaScriptFromString: focus]; 

但這似乎並不奏效。 「j_captcha」是文本字段的名稱。我怎樣才能做到這一點?

回答

0

這奏效了,我

NSString *evalStr = [NSString stringWithFormat:@"setTimeout(function(){document.getElementsByName('j_captcha')[0].focus();},1000);"]; 
[webView stringByEvaluatingJavaScriptFromString:evalStr]; 

這篇文章幫助 - https://stackoverflow.com/a/14268931/653978