layer弹框动态中添加KindEditor编辑器
2019-02-12 11:10:29
由于我要用layer弹出一个意见反馈框,并且反馈内容可以提交图片,所以我使用了layer.open方法,弹出我的html内容
tpl变量是我的html内容,并且里面包含一个#f_content的富文本编辑器,在关闭layer弹框的时候,需要使用remove销毁KindEditor,否则只会弹框时,KindEditor会不生效。 代码如下:
layer.open({ area: '600px', type: 1, title: '尽情吐槽吧', moveType: 1, //拖拽模式,0或者1 closeBtn: 1, shadeClose: true, content: tpl, end: function(){ layer.closeAll(); KindEditor.ready(function(K) { K.remove('#f_content'); }); } }); KindEditor.create('#f_content',{ allowFileManager : true , afterBlur:function(){this.sync();}, items: [ "image", "multiimage", "insertorderedlist", "insertunorderedlist","outdent", "indent", "link","unlink"] //配置kindeditor编辑器的工具栏菜单项 }); }); $(document).delegate("#closeLayer1", 'click', function(event) { layer.closeAll(); KindEditor.ready(function(K) { K.remove('#f_content'); }); });
需注意:
要想动态创建KindEditor在线文本编辑器,必须去掉KindEditor.ready(function(K) {});外部方法。直接使用绑定代码,并且注意:K变为KindEditor
editor = K.create('textarea[name="content"]', { allowFileManager : true }); //错误 editor = KindEditor.create('textarea[name="content"]', { allowFileManager : true }); //正确