关于JqueryEasyUI集合Kindeditor

实现

  因本人js技术有限,试了好久也没搞好,此处略去十万个字。。。

  网上找到一段js代码:

复制代码
 1 (function ($, K) {
 2     if (!K)
 3         throw "KindEditor未定义!";
 4 
 5     function create(target) {
 6         var opts = $.data(target, 'kindeditor').options;
 7         var editor = K.create(target, opts);
 8         $.data(target, 'kindeditor').options.editor = editor;
 9     }
10 
11     $.fn.kindeditor = function (options, param) {
12         if (typeof options == 'string') {
13             var method = $.fn.kindeditor.methods[options];
14             if (method) {
15                 return method(this, param);
16             }
17         }
18         options = options || {};
19         return this.each(function () {
20             var state = $.data(this, 'kindeditor');
21             if (state) {
22                 $.extend(state.options, options);
23             } else {
24                 state = $.data(this, 'kindeditor', {
25                         options : $.extend({}, $.fn.kindeditor.defaults, $.fn.kindeditor.parseOptions(this), options)
26                     });
27             }
28             create(this);
29         });
30     }
31 
32     $.fn.kindeditor.parseOptions = function (target) {
33         return $.extend({}, $.parser.parseOptions(target, []));
34     };
35 
36     $.fn.kindeditor.methods = {
37         editor : function (jq) {
38             return $.data(jq[0], 'kindeditor').options.editor;
39         }
40     };
41 
42     $.fn.kindeditor.defaults = {
43         resizeType : 1,
44         allowPreviewEmoticons : false,
45         allowImageUpload : false,
46         items : [
47             'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline',
48             'removeformat', '|', 'justifyleft', 'justifycenter', 'justifyright', 'insertorderedlist',
49             'insertunorderedlist', '|', 'emoticons', 'image', 'link'],
50         afterChange:function(){
51             this.sync();
52         }
53     };
54     $.parser.plugins.push("kindeditor");
55 })(jQuery, KindEditor);
复制代码

  需要同时引用easyui和kindeditor相关样式和脚本,然后就可以像使用easyui组件一样使用kindeditor:

1   <textarea name="easyui_ditor" id="easyui_ditor" class="easyui-kindeditor" style="width: 100%; height: 200px; visibility: hidden;">EasyUI集合KindEditor</textarea>

  如果你使用的是后台获取设置kindeditor值的话可以使用这个,但是js获取或设置文本框值,上面就不好实现,也试了很多方法没有解决,有关js的大神如果知道方法还请赐教。

  注意创建kindeditor的时候有个afterChange事件,表示更改编辑器的内容发生的事件,这边需要重写下。其实kindeditor不集合到easyui中也是可以使用,只不过没有上面这样创建方便,做了个示例,大家可以看下:

复制代码
 1                 <tr>
 2                     <td>easyui-kindeditor编辑器:</td>
 3                     <td>
 4                         <textarea name="easyui_ditor" id="easyui_ditor" class="easyui-kindeditor" style="width: 100%; height: 200px; visibility: hidden;">EasyUI集合KindEditor</textarea>
 5                         <a href="javascript:void(0)" class="easyui-linkbutton" onclick="">设置</a>
 6                         <a href="javascript:void(0)" class="easyui-linkbutton" onclick="alert(KindEditor.html())">获取</a>
 7                     </td>
 8                 </tr>
 9                 <tr>
10                     <td>kindeditor编辑器:</td>
11                     <td>
12                         <textarea name="txtContent" id="txtContent" style="width: 100%; height: 200px; visibility: hidden;">KindEditor</textarea>
13                         <a href="javascript:void(0)" class="easyui-linkbutton" onclick="editor.html('我在设置KindEditor内容');">设置</a>
14                         <a href="javascript:void(0)" class="easyui-linkbutton" onclick="alert(editor.html())">获取</a>
15                     </td>
16                 </tr>
复制代码

  js代码:

复制代码
 1         //编辑器
 2         var editor;
 3         KindEditor.ready(function (K) {
 4             editor = K.create('textarea[name="txtContent"]', {
 5                 allowFileManager: true,
 6                 resizeType: 1,
 7                 allowPreviewEmoticons: false,
 8                 items: [
 9                     'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline',
10                     'removeformat', '|', 'justifyleft', 'justifycenter', 'justifyright', 'insertorderedlist',
11                     'insertunorderedlist', '|', 'emoticons', 'image', 'link']
12             });
13         });
复制代码

  效果:


本文转自田园里的蟋蟀博客园博客,原文链接:http://www.cnblogs.com/xishuai/p/3628923.html,如需转载请自行联系原作者

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值