gpt4 book ai didi

javascript - UIWebView和javascript需要加载数据

转载 作者:行者123 更新时间:2023-11-30 13:26:01 26 4
gpt4 key购买 nike

我有一个名为 proof.html 的文件,如下所示:

    <title>{title}</title>
<link rel="stylesheet" type="text/css" href="{cssURL}" />
<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;" />
<meta name="apple-mobile-web-app-capable" content="yes" />
</head>
<body class="{language} {custom}">
<div class="FeedTitle">{feedTitle}<br /><span><em>via</em> RSS</span></div>
<div class="Published">{date}</div>
<div class="Title"><a href="{sourceURL}">{title}</a></div>
<div class="Author">{author}</div>
<div class="RSS">{text}</div>
<div class="Original"><a href="{sourceURL}"></a></div>

稍后我使用以下命令将其加载到我的 UIWebViev 中:

 [doc loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"proof" ofType:@"html"]isDirectory:NO]]];

现在我无法理解如何将 {author} 替换为新闻作者的真实姓名...如何将它传递给我的 UIWebView?有人可以分享一个例子吗?谢谢。

最佳答案

您需要使用 JavaScript 来执行此操作,方法是 stringByEvaluatingJavaScriptFromString:

例如:

[yourWebView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"document.getElementById('Author').innerHTML = '%@';",authorsName]];

注意:对于上面的例子,你需要给你的 div 添加一个 id 属性。

关于javascript - UIWebView和javascript需要加载数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8443004/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com