之前找前端一块联调,优化展示题目信息Html的方法
NSString *contentStr = model.content;
contentStr = [contentStr stringByReplacingOccurrencesOfString:@"width" withString:@"wid"];
// 去除样式
NSString *htmlContent =[NSString stringWithFormat:@"<style type=\"text/css\">\n"
"table{font-size: 14px !important;color: #666 !important;line-height:20px !important;}"
"#div123{font-size:14px !important;line-height:20px !important;color:#666 !important;font-family: \"Microsoft Yahei\", \"微软雅黑\";}\n"
" </style>\n<div id=div123>%@</div> <script type=\"text/javascript\">\n"
"\t\tvar ele =document.getElementById('div123').getElementsByTagName('*');\n"
"\t\tfor(var i=0;i<ele.length;i++){\n"
"\t\t\tif (typeof ele[i].getAttribute('style') == \"string\") {\n"
"\t var str = ele[i].getAttribute('style');\n"
"\t var box = /font-size:.{2,5}p[xt];{0,1}/;"
"\t ele[i].setAttribute(\"style\", str.replace(box, \"\"));\n"
"\t }\n"
"\t\t}\n"
"\n"
"\n"
"\t</script>",contentStr];
[_webView loadHTMLString:htmlContent baseURL:nil];
网友评论