百度ueditor富文本编辑器插入html代码问题

    xiaoxiao2021-03-25  116

    今天下午想把ueditor保存的html代码从数据库取出来放回到ueditor中编辑,然后就一直放不进去,通过不断地测试终于成功,接下来我讲一下我的解决方法

    从后台取到值后想在js中直接用

    UE.getEditor('editor').execCommand('insertHtml', '${queryArtid.aContent }');

    方法插入, 但在${queryArtid.aContent }数据的两边加了 ’ ’ 后,原本的html代码符号就乱了,因此我们不能直接把数据给它,得通过一个中转站,不再使用 ’ ’ ;

    <!-- 现将博文内容放到code中,然后ueditor再从这里取值 --> <code id="testcon" style="display:none;"> ${queryArtid.aContent } </code>

    <code>标签保持代码原样,不会被编译; 然后就再次使用赋值方法

    UE.getEditor('editor').execCommand('insertHtml', $('#testcon').html());

    到了这一步,哎?怎么还是没用呢,不要急,还有一步 就是延迟赋值的时间,等js文件都加载完后再插入值,方法如下

    $(function(){ window.setTimeout(setContent,1000);//一秒后再调用赋值方法 }); //给ueditor插入值 function setContent(){ UE.getEditor('editor').execCommand('insertHtml', $('#testcon').html()); }

    这是我编辑前的样子

    这是点击编辑后的样子

    欢迎转载,但请注明出处!

    转载请注明原文地址: https://ju.6miu.com/read-24802.html

    最新回复(0)