用户注册



邮箱:

密码:

用户登录


邮箱:

密码:
记住登录一个月忘记密码?

发表随想


还能输入:200字

苏起    -  云代码空间

—— 干一件你感兴趣的事,永远不觉得累!

动态创建多个KindEditor编辑器

2014-07-31|5616阅||

摘要:动态创建多个KindEditor编辑器

首先写这篇文章是为了以后自己使用,其中的逻辑方式可能不是最好的,因本人也是菜鸟一只。言归正传。
创建多个编辑器是因为有个项目类似于微博的评论的功能,一个页面会有多个文章或广播就需要多个评论,根据加载的文章数来动态创建多个编辑器了,我的方式如下:
 var K = window.KindEditor;//编辑器全局变量
 var kinditerArry = new Array(4);//多个编辑器的数组,此处因为我数据绑定控件一页最多显示4个文章所以就写死了长度为4的数组
 var kinditerindex = 0; //编辑器初始索
下面是关键:
dlstCircleArticle是个DIV里面包含了根据数据绑定的多个多行文本框,所以只需循环文本框来创建多个编辑器,至于编辑器的初始化可以自己去网上找相关文章
这里不多做说明了
 $("#dlstCircleArticle").find("textarea").each(function (index, item) {
                var objId = $(this).attr("id");
                kinditerArry[kinditerindex] = K.create('#' + objId, {
                    cssPath: '../kindeditor-4.1.10/plugins/code/prettify.css',
                    uploadJson: 'ashx/upload_json.ashx',
                    fileManagerJson: 'ashx/file_manager_json.ashx',
                    allowFileManager: false,
                    allowImageRemote: false,
                    //得到焦点事件
                    afterFocus: function () {
                        self.edit = edit = this; var strIndex = self.edit.html().indexOf("@我也说一句"); if (strIndex != -1) { self.edit.html(self.edit.html().replace("@我也说一句", "")); }
                    },
                    //值改变事件
                    afterChange: function () {

                    },
                    width: "95%",
                    minheight: 30,
                    height: 30,
                    resizeType: 0,
                    //失去焦点事件
                    afterBlur: function () { this.sync(); self.edit = edit = this; if (self.edit.isEmpty()) { self.edit.html("@我也说一句"); } },   //关键  同步KindEditor的值到textarea文本框   解决了多个editor的取值问题
                    items: [
		            'emoticons'

	                   ],
                    afterCreate: function () {
                        var self = this;
                        self.html("@我也说一句");
                        K.ctrl(document, 13, function () {
                            K('form[name=example]')[0].submit();
                        });
                        K.ctrl(self.edit.doc, 13, function () {
                            self.sync();
                            K('form[name=example]')[0].submit();

                        });
                    }
                });
                kinditerindex++;

            });

        })

顶 8踩 6收藏
文章评论
    发表评论