如何将 UITextField 中的一些文本实际放入 iOS 应用程序中 UIWebView 的表单中?也许可以调用 JavaScript 字符串来输入文本?
谢谢!
最佳答案
就像 Matt H 建议的那样,您需要注入(inject) javascript。所以这个问题基本上有两个部分。首先你有你的 Objective-C 。
NSString *username = @"Fred";
NSString *password = @"pAssw0rd";
NSString *jsCallBack = [NSString stringWithFormat:@"updateWebForm('%@,%@');",username,password];
[self.webView stringByEvaluatingJavaScriptFromString:jsCallBack];
然后你将拥有你的 javascript 函数,我将我的函数放在 .js 文件中,我的 webview 页面链接到该文件。
updateWebForm(username,password)
{
//here is where you will assign whatever html/javascript needed for your form.
}
关于iphone - 将文本添加到 UIWebView 文本框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7840206/