Iphone UIWebView stringByEvaluatingJavaScriptFromString包装标记与其他标记
假设我有这样一个HTML:Iphone UIWebView stringByEvaluatingJavaScriptFromString包装标记与其他标记,iphone,html,objective-c,ipad,uiwebview,Iphone,Html,Objective C,Ipad,Uiwebview,假设我有这样一个HTML: <html> <form> <input type="button" id="Signature8" pdfFieldName="Signature8" onclick="document.location='pdz://signatureTapped?name=Signature8'" /> </form> </html> 应该这样称呼: [f injectCode:[NSString stri
<html>
<form>
<input type="button" id="Signature8" pdfFieldName="Signature8" onclick="document.location='pdz://signatureTapped?name=Signature8'" />
</form>
</html>
应该这样称呼:
[f injectCode:[NSString stringWithFormat:@"<img src=\"%@.png\" id=\"%@\">", f.identifier, f.identifier] intoWebView:self.webView withEndCode:@"</img>"];
[f injectCode:[NSString stringWithFormat:@',f.identifier,f.identifier]插入webView:self.webView withEndCode:@];
(鉴于f是一个包含该签名8字段的名称、标识符等的对象)。
问题是:这不起作用。当我调试它时,我可以看到innerhtml被填充,我可以看到newCode实际上是正确的(至少对我来说),我认为用newCode分配outerHTML的行以及所有这些应该相应地替换整个HTML的行。为了验证,我将其注销到控制台。是 啊什么都没变
有人能告诉我我做错了什么吗?我不能真正使用jQuery或任何其他框架,因为代码应该从第三方获得其HTML表单,他们不必使用jQuery或类似的东西。您只是缺少新HTML的引号:
NSString* newCode = [NSString stringWithFormat:@"document.forms[0].%@.outerHTML=\"%@%@%@\";", self.identifier, code, innerhtml, endCode];
请记住,outerHTML需要一个字符串。不幸的是,没有,但我找到了一个带有代理的解决方案,可以在获取HTML之前动态修改HTML。工作也一样:-)
[f injectCode:[NSString stringWithFormat:@"<img src=\"%@.png\" id=\"%@\">", f.identifier, f.identifier] intoWebView:self.webView withEndCode:@"</img>"];
NSString* newCode = [NSString stringWithFormat:@"document.forms[0].%@.outerHTML=\"%@%@%@\";", self.identifier, code, innerhtml, endCode];