OGeek|极客世界-中国程序员成长平台

标题: iphone - 向 UIWebView 文本框添加文本 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 17:59
标题: iphone - 向 UIWebView 文本框添加文本

如何在我的 iOS 应用程序中将 UITextField 中的一些文本以物理方式放入 UIWebView 的表单中?也许可以调用一个javascript字符串来输入文本?

谢谢!



Best Answer-推荐答案


就像 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/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4