how to clear ckeditor with jquery

僤鯓⒐⒋嵵緔 提交于 2019-11-30 17:47:05
ghostCoder

CKEDITOR.instances.editor1.setData('');

Where editor1 is the id of your CKEDITOR field

The below code clears the value in the ckeditor textarea. This will works 4.4 version also.

      CKEDITOR.instances['content'].setData('');

Content is the id of the particular text-area.

Try it may helpful.

function CKupdate(){
    for ( instance in CKEDITOR.instances ){
        CKEDITOR.instances[instance].updateElement();
    }
    CKEDITOR.instances[instance].setData('');
}   

$.ajax({
   url: $('#CommunicationForm').attr("action"),
   type: $('#CommunicationForm').attr("method"),
   data: $('#CommunicationForm').serialize(),
   success: function (e) {
       if (e.error) {
          alert(e.error);
       } else {
          //Doing Clear here                          
          CKupdate();
       }
   },
   error: function (jqXHR, Status, text) {
        alert("error! " + text);
   }   
});

Call CKupdate() function when when you want to clear CKEditor text.

In my code i had to change the text in the ckeditor programmatically but it did not work until i did a defered set. This may be helpful.

_.defer(function () {
    it._controls.wysiwyg.setData(bodyText); // by the direct reference
    //CKEDITOR.instances.editor1.setData(''); // or this way like in the example
}); 
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!