这两天做项目需用富文本编辑器编辑相应内容的功能,在做修改编辑内容时添加的表格以标签的形式展示了出来,开始以为是后端数据处理有问题,使用PHP的翻转译函数html_entity_decode()没有任何变化;随后前端打印出返回值时发现,当传数据传到前端页面时又被转译了(无语……)
$arr['content']= html_entity_decode($arr['content']);
$arr['content']=stripslashes($arr['content']);
之后参考了 weixin_34392906 的 JS实现HTML标签转义及反转义 (https://blog.csdn.net/weixin_34392906/article/details/92381544?utm_medium=distribute.pc_relevant.none-task-blog-baidujs_title-0&spm=1001.2101.3001.4242) 后,问题完美解决,
jQuery代码
var ue = UE.getEditor('editor');
var content = "{$list.content}";
content =HTMLDecode(content);
ue.addListener("ready", function () {
// editor准备好之后才可以使用
ue.setContent(content);
})
//标签翻转
function HTMLDecode(text) {
var temp = document.createElement("div");
temp.innerHTML = text;
var output = temp.innerText || temp.textContent;
temp = null;
return output;
}
记录相应问题,加深映象,共勉之。