Ckeditor事件绑定

这段时间使用js+cookies进行自动草稿保存,个人觉的,这些全在客户端处理比较的好,所以没有使用AJAX+数据库的自动草稿保存方法。

结果出现Ckeditor无法绑定onkeyup,onselect,onclick事件的问题,查看了Ckeditor的API,发现如下说明:

instanceReady.ckeditor: fired when the editor is created, but before any callback being passed to the ckeditor() method. 
setData.ckeditor: fired when data is set into the editor. 
getData.ckeditor: fired when data is fetched from the editor. The current editor data is also passed in the arguments. 
destroy.ckeditor: fired when the editor gets destroyed. It can be used, for example, to execute some cleanup on the page. 

估计是使用instanceReady,然后在网上查找了一翻,要找这东西的事件绑定,真难。找了N久,找到一个Ckeditor二次开发的例子,经过修改,终于成功。下面是绑定方法。

首先是文本编辑器的绑定:

<textarea name="Content" rows="10" cols="20" id="Content"></textarea>
  <script type="text/javascript">
  var editor = CKEDITOR.replace('Content', {
  language: 'zh-cn', //简体中文  
  width: 739,
  height: 125,
  toolbar: 'DJArticle'//工具栏的名称
  });  
  </script>

这样,编辑器就出现了。然后是绑定 onkeyup,onselect,onclick事件。

                <script type="text/javascript">
//<![CDATA[
                    CKEDITOR.instances["Content"].on("instanceReady", function () {
                        //set keyup event
                        this.document.on("keyup", AutoSave);
                        //and click event
                        this.document.on("click", AutoSave);
                        //and select event
                        this.document.on("select", AutoSave);
                    });


                    function AutoSave() {//相应的操作过程,可以按下面写,也可以按一般javascript过程写。
                        CKEDITOR.tools.setTimeout(function () {
                            alert("10101010");
                        }, 0);
                    }   
//]]>
                            </script>

至此,绑定完成!

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值