场景:后台返回整个动态的html页面,前端通过获取渲染出来,进行转义解析
实现方式:
通过接口获取返回的html的数据,document.getElementById(“container”).innerHTML = this.decodeUnicode(接口返回的数据);
js方法
decodeUnicode(str) {
str = str.replace(/\\/g, "%");
//转换中文
str = unescape(str);
//将其他受影响的转换回原来
str = str.replace(/%/g, "\\");
//对网址的链接进行处理
str = str.replace(/\\n/g, "");
str = str.replace(/\\t/g, "");
str = str.replace(/\\/g, "");
return str;
}
对html进行解析,因为好多转义符,所以需要一个个解析出正确的内容

本文介绍了一种通过后台返回HTML动态页面数据,并由前端进行渲染的方法。具体实现中使用了JavaScript来处理转义字符,确保页面能正确显示。此方法适用于需要在前端展示动态生成的HTML内容的场景。
897

被折叠的 条评论
为什么被折叠?



