iOS中在同一个HTML中加载多个JS的方法参考

源码来自:Zed Said Studio

//Define correct bundle for loading resources
NSBundle* bundle = [NSBundle bundleForClass:[ZSSRichTextEditor class]];

//Create a string with the contents of editor.html
NSString *filePath = [bundle pathForResource:@"editor" ofType:@"html"];
NSData *htmlData = [NSData dataWithContentsOfFile:filePath];
NSString *htmlString = [[NSString alloc] initWithData:htmlData encoding:NSUTF8StringEncoding];

//Add jQuery.js to the html file
NSString *jquery = [bundle pathForResource:@"jQuery" ofType:@"js"];
NSString *jqueryString = [[NSString alloc] initWithData:[NSData dataWithContentsOfFile:jquery] encoding:NSUTF8StringEncoding];
htmlString = [htmlString stringByReplacingOccurrencesOfString:@"<!-- jQuery -->" withString:jqueryString];

//Add JSBeautifier.js to the html file
NSString *beautifier = [bundle pathForResource:@"JSBeautifier" ofType:@"js"];
NSString *beautifierString = [[NSString alloc] initWithData:[NSData dataWithContentsOfFile:beautifier] encoding:NSUTF8StringEncoding];
htmlString = [htmlString stringByReplacingOccurrencesOfString:@"<!-- jsbeautifier -->" withString:beautifierString];

//Add ZSSRichTextEditor.js to the html file
NSString *source = [bundle pathForResource:@"ZSSRichTextEditor" ofType:@"js"];
NSString *jsString = [[NSString alloc] initWithData:[NSData dataWithContentsOfFile:source] encoding:NSUTF8StringEncoding];
htmlString = [htmlString stringByReplacingOccurrencesOfString:@"<!--editor-->" withString:jsString];

[self.editorView loadHTMLString:htmlString baseURL:self.baseURL];

从上面可以看出,在HTML中,写了要被替换的字符串“,然后用JS 替换。

全部评论

相关推荐

脾气小祖宗:这简历摸到都得狠狠地消毒液洗手😂
点赞 评论 收藏
分享
稚名不带撇:感觉学院本就已经废了,不是能不能进公司的问题了,是根本就没有啥面试,boss沟通了一千多,回我消息的才89,面试的才二十几个,但基本上都是小公司点击就送,唯一一次有1000+的公司面试,面的很好全回答出来了,项目这块个人感觉也说的不错,甚至面试官最后还直接给我介绍公司业务和看公司系统这些,介绍的也比较详细,说了40分钟到一个小时左右,说怕给我offer我不喜欢这种模式啥啥啥的,鼠鼠以为应该稳了,但是最后还是挂了,我问我们老师他说这种情况大概率是学历比你高的出现了,虽然可能问题没有全回答出来,但是学历把你爆了
秋招,不懂就问
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务