从后台取到值后想在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()); }