先把内容放入一个input中
<input id="detail" type="hidden" value="${sysCarousel.detail}"/>
然后判断是插入还是修改
如果是修改才会向富文本编辑器中嵌入html代码
<script type="text/plain" id="chvGoodsRemark" name="detail" style="margin-bottom:100px;width:1024px;height:700px;"></script> <c:if test="${sysCarousel.id==null}"> <script type="text/javascript"> UE.getEditor("chvGoodsRemark", { autoClearinitialContent:false,wordCount:true,elementPathEnabled:true,autoHeightEnabled:false,maximumWords:0,fullscreen:false,initialFrameWidth:1000,initialFrameHeight:320 }); </script> </c:if> <c:if test="${sysCarousel.id!=null}"> <script type="text/javascript"> UE.getEditor("chvGoodsRemark", { autoClearinitialContent:false,wordCount:true,elementPathEnabled:true,autoHeightEnabled:false,maximumWords:0,fullscreen:false,initialFrameWidth:1000,initialFrameHeight:320 }); </script> </c:if>
然后js控制插入代码
$(function(){ window.setTimeout(setContent,1000);//一秒后再调用赋值方法 }); //给ueditor插入值 function setContent(){ var a =$('#detail').val(); UE.getEditor('chvGoodsRemark').execCommand('insertHtml',a); }
如果是想在html页面中直接嵌入一段html(比如<p>123<p>显示123)代码,直接jquery获取这段代码,或者手写一段代码,通过js函数向<text></text>里面赋值即可,例子如下:
<text id="showInfo2"></text>
var divshow = $("#showInfo2"); divshow.text("");// 清空数据 divshow.append(data); // 添加Html内容,不能用Text 或 Val
原创文章,作者:奋斗,如若转载,请注明出处:https://blog.ytso.com/tech/pnotes/11513.html