搞了很久的KindEditor

来源:互联网 发布:领航一号软件下载 编辑:程序博客网 时间:2024/04/30 00:08

虽然KindEditor提供了将textarea同步到KindEditor的sync()方法,但是在实际的应用中还是在这个地方遇到了一点问题,

最终的解决方法是:将KindEditor在页面加载时就加载,源码是这样:

在页面初始化<script>        $(function () {            kindEditorInit();        });    </script>在js文件中写实现var editor;function kindEditorInit() {    $.post('/SubForm/GetQuestionListFromDB'/*, { subFormID: 2 }*/, function (data) {        editor.html(data);    });    KindEditor.ready(function (k) {        editor = k.create('#questionEditor', {            width: 1620,            height: 690,            fontSizeTable: ['9px', '10px', '12px', '14px', '16px', '18px', '24px', '32px'],            items: [                'undo', 'redo', '|',                'cut', 'copy', 'paste', 'preview', '|',                'plainpaste', 'wordpaste', '|',                'justifyleft', 'justifycenter', 'justifyright', 'justifyfull', '|',                'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', '|',                'subscript', 'superscript',                'quickformat', 'selectall', '|',                'fullscreen', '|',                'strikethrough', 'removeformat', '|',                'table', 'hr', 'emoticons', 'pagebreak'            ],            resizeType: 0,            afterCreate: function () {                var self = this;                //self.sync();                k.ctrl(document, 13, function () {                    self.sync();                    k('textarea[name=questionEditor]')[0].submit();                });                k.ctrl(self.edit.doc, 13, function () {                    self.sync();                    k('textarea[name=questionEditor]')[0].submit();                });            },            afterChange: function () {            },            afertBlur: function () {                var self = this;                //self.sync();                k.ctrl(document, 13, function () {                    self.sync();                    k('textarea[name=questionEditor]')[0].submit();                });                k.ctrl(self.edit.doc, 13, function () {                    self.sync();                    k('textarea[name=questionEditor]')[0].submit();                });            }        });    });}
html部分:
<div>                <form id="questionEditorForm">                    <textarea id="questionEditor" name="content" style="width: 1620px; height: 690px; background-color: #FFFFFF; display: block">                    </textarea>                    <div style="margin: 10px 0">                        <a href="javascript:editQuestionList()" class="easyui-linkbutton">编辑</a>                        <a href="javascript:saveQuestionList()" class="easyui-linkbutton">保存</a>                        <a href="javascript:cancelQuestionList()" class="easyui-linkbutton">退出</a>                    </div>                </form>            </div>




原创粉丝点击