先把內容放入一個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
<%@ tag language="java" pageEncoding="UTF-8"%> <%@ include file="/WEB-INF/views/include/taglib.jsp"%> <%@ attribute name="input" type="java.lang.String" required="true" description="輸入框"%> <%@ attribute name="value" type="java.lang.String" required="true" description="值"%> <%@ attribute name="maxWidth" type="java.lang.String" required="false" description="最大寬度"%> <%@ attribute name="maxHeight" type="java.lang.String" required="false" description="最大高度"%> <script id="${input}_editor" name="${input}" type="text/plain" class="required" style="width:95%;height:600px;"></script> <script type="text/javascript"> UE.getEditor('${input}_editor').addListener("ready", function () { setTimeout('${input}init()',500); }); /* $(function(){ setTimeout('${input}init()',500); }); */ function ${input}init(){ var html = $('#${input}').val(); UE.getEditor('${input}_editor').execCommand('insertHtml',html); } </script> <script type="text/javascript"> //實例化編輯器 //建議使用工廠方法getEditor創建和引用編輯器實例,如果在某個閉包下引用該編輯器,直接調用UE.getEditor('editor')就能拿到相關的實例 var ue = UE.getEditor('${input}_editor'); </script> <input id="${input}" type="hidden" value="${value}" class="required"/>
<script type="text/javascript" src="${ctxStatic}/ueditor/ueditor.config.js"></script> <script type="text/javascript" src="${ctxStatic}/ueditor/ueditor.all.js"></script> <script type="text/javascript" charset="utf-8" src="${ctxStatic}/ueditor/lang/zh-cn/zh-cn.js"></script>
