KindEditor 初始化编辑内容 默认被置左,请大神帮忙看看

诠释这低调 发布于 2015/02/03 09:47
阅读 1K+
收藏 0

KindEditor 初始化编辑内容, 默认被置左,html数据没问题,但是初始化后默认被重置,不知道是控件本身的问题还是代码的问题


代码如下:

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>编辑活动</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" type="text/css" href="${ctx}/scripts/miniui/themes/icons.css" />
<link href="${ctx}/rs/css/demo.css" rel="stylesheet" type="text/css" />
<script src="${ctx}/rs/scripts/boot.js" type="text/javascript"/>
<script src="${ctx}/rs/scripts/jQueryValidate/jquery.js" type="text/javascript"></script>
<script src="${ctx}/rs/scripts/jquery.form.js" type="text/javascript"></script>
<link rel="stylesheet" href="${ctx}/rs/scripts/kindeditor/themes/default/default.css" />
<link rel="stylesheet" href="${ctx}/rs/scripts/kindeditor/plugins/code/prettify.css" />
<script charset="utf-8" src="${ctx}/rs/scripts/kindeditor/kindeditor.js"></script>
<script charset="utf-8" src="${ctx}/rs/scripts/kindeditor/lang/zh_CN.js"></script>
<script charset="utf-8" src="${ctx}/rs/scripts/kindeditor/plugins/code/prettify.js"></script>
</head>
<body>
 <form id="form1" method="post" action="${ctx}/campaign/save.htm" enctype="multipart/form-data">
  <table width="100%">
   <tr>
    <td class="td_head"><label for="textbox1$text">标题:</label></td>
    <td>
        <input class="mini-hidden" id="id" name="id"/>
        <input id="title" name="title" class="mini-textbox" style="width: 400px;" vtype="maxLength:100" required="true"/>
    </td>
   </tr>
   <tr>
    <td class="td_head"><label for="textbox1$text">类别:</label></td>
    <td>
                    <input id="categoryIds" name="categoryIds" class="mini-treeselect" url="${ctx}/categoryType/tree" valueField="id" textField="name" parentField="parentId"  multiSelect="true" required="true"/>
    </td>
   </tr>
   <tr>
                <td class="td_head">是否参与:</td>
                <td>
                   <input id="partake" name="partake"  class="mini-combobox" textField="text" valueField="id" data="[{id:0,text:'否'},{id:1,text:'是'}]"/>
                </td>
            </tr>
   <tr>
    <td class="td_head"><label for="textbox1$text">封面:</label></td>
    <td>
        <input class="mini-hidden" id="cover" name="cover"/>
        <input class="mini-htmlfile" id="cfile" name="cfile" limitType="*.jpg;*.png"/>
        <span style="color: red">支持图片格式jpg或png,尺寸155*155</span>
    </td>
   </tr>
   <tr>
    <td class="td_head"><label for="textbox1$text">活动时间:</label></td>
    <td>
        <input id="startDate" name="startDate" class="mini-datepicker" required="true" /> - <input id="endDate" name="endDate" class="mini-datepicker" required="true" />
    </td>
   </tr>
   <tr>
    <td class="td_head"><label for="textbox1$text">发起人:</label></td>
    <td>
        <input id="sponsor" name="sponsor" class="mini-textbox" style="width: 200px;" vtype="maxLength:100" required="true"/>
    </td>
   </tr>
   <tr>
    <td class="td_head"><label for="textbox1$text">内容:</label></td>
    <td>
        <textarea id="content" name="content" cols="100" rows="10" style="width:90%;height:270px; float:left;">${campaign.content}</textarea>
    </td>
   </tr>
   <tr>
    <td colspan="2"><label for="textbox1$text">&nbsp;</label></td>
   </tr>
   <tr>
    <td colspan="2" align="center">
     <input value="提交" type="button" onclick="submitForm()" />
     <input value="重置" type="button" onclick="resetForm()" />
    </td>
   </tr>
  </table>
 </form>
<script type="text/javascript">
    mini.parse();
   
    var form = new mini.Form("#form1");
   
    function SetData(data){
        //跨页面传递的数据对象,克隆后才可以安全使用
        data = mini.clone(data);
        form.setData(data);
    }

    var editor;
    KindEditor.ready(function(K) {
     editor = K.create('textarea[name="content"]', {
      cssPath : '${ctx}/rs/scripts/kindeditor-4.1.10/plugins/code/prettify.css',
      uploadJson : '${ctx}/kindeditor-accessory-upload.htm',
      fileManagerJson : '${ctx}/rs/scripts/kindeditor-4.1.10/util/file_manager_json.jsp',
      allowFileManager : true,
      afterCreate : function() {
       var self = this;
       K.ctrl(document, 13, function() {
        self.sync();
//         document.forms['form1'].submit();
       });
       K.ctrl(self.edit.doc, 13, function() {
        self.sync();
//         document.forms['form1'].submit();
       });
      }
     });
     prettyPrint();
    });

    function submitForm(){
        //提交表单数据
        form.validate();
        if(form.isValid()){
         editor.sync(); //同步
         var forms = $('#form1'),messageid = null;
      var options = {
       dataType : "json",
       timeout: 600000,//限制请求的时间,当请求大于10分钟后,跳出请求
       beforeSubmit : function() {
        messageid = mini.loading("正在进行发布操作, 请稍候...", "提示");
       },
       success : function(result) {
        if(messageid){
         mini.hideMessageBox(messageid);
        }
        if(result){
         alert('发布成功!');
         onOk();
        }else{
         alert('发布失败!');
        }
       },
       error : function(result) {
        if(messageid){
         mini.hideMessageBox(messageid);
        }
        alert('发布失败!');
       }
      };
      forms.ajaxSubmit(options);
      return false;
        }else{
         return;
        }
    }
   
    //重置表单
    function resetForm() {
//      form.reset();
        mini.get("title").setValue("");
        mini.get("categoryIds").setValue("");
        mini.get("cfile").setValue("");
        mini.get("startDate").setValue("");
        mini.get("endDate").setValue("");
        mini.get("sponsor").setValue("");
     editor.html("");
    }

    //关闭窗口
    function CloseWindow(action) {
        if (window.CloseOwnerWindow)
            return window.CloseOwnerWindow(action);
        else
            window.close();
    }

    //确认
    function onOk() {
        CloseWindow("ok");
    }
   
    //取消
    function onCancel() {
        CloseWindow("cancel");
    }
</script>
</body>
</html>

加载中
返回顶部
顶部