上火啊,替换字符串,HTML,

-(void)webViewDidFinishLoad:(UIWebView *)webView

{

    JSContext *jsContext = [webView valueForKeyPath: @"documentView.webView.mainFrame.javaScriptContext"];

    jsContext[@"ocObj"] = self;

    //设置高度

    JSValue *jHeight  = [jsContext evaluateScript:@"document.body.scrollHeight"];

    self.mWebView.scrollView.contentSize = CGSizeMake(screenW, [jHeight toDouble]);

 

    JSValue *kContent = [jsContext evaluateScript:@"document.getElementById('guligei').innerHTML"];

    NSString *kName = [kContent toString];

    NSString *replaced = [kName stringByReplacingOccurrencesOfString:@"${studentName}" withString:@"战歌"];

    NSString *jsString = [NSString stringWithFormat:@"document.getElementById('stuName').innerHTML='%@'",replaced];

    [jsContext evaluateScript:jsString];

}

 

 

                    returnStr =[returnStr stringByReplacingOccurrencesOfString:@"${studentName}" withString:SharedAppDelegate.userInfo.name];

原文地址:https://www.cnblogs.com/guligei/p/4773556.html