今天手下有个问:当用户填写提交后,再次显示提交页面时,该页面的UEditor编辑器需要设置成不可编辑,怎么实现?
可以用后台调用前台js的方式实现:
例如:
前台页面:
<div style="">请将答案写到下面:</div><asp:HiddenField ID="myEditorHidden" runat="server" /><div style="text-align:left;padding-top:5px;"><%--文本编辑器--%><div id="myEditor" style="width:100%;height:150px;" ></div></div>
前台实现编辑器初始化和内容传递js:
<script type="text/javascript">var ue = UE.getEditor('myEditor', {toolbars: [[ 'undo', 'redo', '|','bold', 'italic', 'underline', 'fontborder', 'strikethrough', 'superscript', 'subscript', 'removeformat', 'formatmatch', 'autotypeset', 'blockquote', 'pasteplain', '|', 'forecolor', 'backcolor', 'insertorderedlist', 'insertunorderedlist', 'selectall', 'cleardoc', '|','rowspacingtop', 'rowspacingbottom', 'lineheight', '|','customstyle', 'paragraph', 'fontfamily', 'fontsize', '|','directionalityltr', 'directionalityrtl', 'indent', '|','justifyleft', 'justifycenter', 'justifyright', 'justifyjustify', '|', 'touppercase', 'tolowercase', '|','link', 'unlink', 'anchor', '|', 'imagenone', 'imageleft', 'imageright', 'imagecenter', '|','simpleupload', 'insertimage', 'scrawl', 'insertframe', 'insertcode', 'pagebreak', 'template', 'background', '|','horizontal', 'date', 'time', 'spechars', 'snapscreen', 'wordimage', '|','inserttable', 'deletetable', 'insertparagraphbeforetable', 'insertrow', 'deleterow', 'insertcol', 'deletecol', 'mergecells', 'mergeright', 'mergedown', 'splittocells', 'splittorows', 'splittocols', 'charts', '|','print', 'preview', 'searchreplace', 'help', 'drafts']],allHtmlEnabled: false,//提交到后台的数据是否包含整个html字符串autoHeightEnabled: false,autoFloatEnabled: true,allowDivTransToP: false//阻止div标签自动转换为p标签});function insertUedit() {ue.ready(function () {// alert("tt");var result = document.getElementById("<%=myEditorHidden.ClientID %>").value;UE.getEditor('myEditor').setContent(result, false);UE.getEditor('myEditor').setDisabled();console.log(result);});}</script>
上面的UE.getEditor('myEditor').setDisabled();即设置该编辑器不可编辑。
后台调用前台的js实现配置参数:
ClientScript.RegisterStartupScript(ClientScript.GetType(), "myScript", "<script>window.onload=function(){insertUedit();}</script>");//调用前台的js