这段时间使用js+cookies进行自动草稿保存,我的觉的,这些全在客户端处理比较的好,因此没有使用AJAX+数据库的自动草稿保存方法。javascript
结果出现Ckeditor没法绑定onkeyup,onselect,onclick事件的问题,查看了Ckeditor的API,发现以下说明:html
- 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二次开发的例子,通过修改,终于成功。下面是绑定方法。java
首先是文本编辑器的绑定:数据库
- <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事件。cookie
- <script type="text/javascript">
-
- 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>
至此,绑定完成!编辑器