在使用富文本编辑器来保存数据时,传到后台的数据是以带标签的html文本来保存的,这时候需要用到html的解码和加码来作中间的桥梁来转换数据。下面是前台JS

的加解码方法:

function HTMLEncode(html) {
            var temp = document.createElement("div");
            (temp.textContent != null) ? (temp.textContent = html) : (temp.innerText = html);
            var output = temp.innerHTML;
            temp = null;
            return output;
        }

function HTMLDecode(text) {
            var temp = document.createElement("div");
            temp.innerHTML = text;
            var output = temp.innerText || temp.textContent;
            temp = null;
            return output;
        }

同时推荐一个比较好用的富文本编辑器(wangEditor),这是一个在github上开源的插件,界面简洁,功能完整同时还有全套的中文参考Doc。

 

相关文章:

  • 2021-05-19
  • 2022-01-15
  • 2022-12-23
  • 2022-12-23
  • 2021-10-11
  • 2021-07-19
  • 2022-12-23
猜你喜欢
  • 2021-09-25
  • 2021-12-01
  • 2021-12-28
  • 2022-12-23
  • 2021-07-21
  • 2022-12-23
相关资源
相似解决方案