搞了很久的KindEditor

1 篇文章 0 订阅
1 篇文章 0 订阅

虽然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>






评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值