這段時間使用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>
至此,綁定完成!編輯器