how to clear ckeditor with jquery

ⅰ亾dé卋堺 提交于 2019-11-30 16:45:41

问题


How can i clear the ckeditor textarea with jquery at the click of a button/link?

I have tried this : $("textarea.editor").val(''); and $("textarea.editor1").val(''); i tried with the 1 at the end because of this line when init the editor $ckeditor->editor('editor1', $nDetails); in PHP

Any help would be greatly appreciated.

<p>Details: 

    <?php

    // Helper function for this sample file.
    function printNotFound( $ver )
    {
        static $warned;

        if (!empty($warned))
            return;

        echo '<p><br><strong><span class="error">Error</span>: '.$ver.' not found</strong>. ' .
            'This sample assumes that '.$ver.' (not included with CKFinder) is installed in ' .
            'the "ckeditor" sibling folder of the CKFinder installation folder. If you have it installed in ' .
            'a different place, just edit this file, changing the wrong paths in the include ' .
            '(line 57) and the "basePath" values (line 70).</p>' ;
        $warned = true;
    }



    include_once '../ckeditor/ckeditor.php' ;
    require_once '../ckfinder/ckfinder.php' ;

    // This is a check for the CKEditor class. If not defined, the paths in lines 57 and 70 must be checked.
    if (!class_exists('CKEditor'))
    {
        printNotFound('CKEditor');
    }
    else
    {
        $initialValue = $pageContent;

        $ckeditor = new CKEditor( ) ;
        $ckeditor->basePath = '../ckeditor/' ;

        // Just call CKFinder::SetupCKEditor before calling editor(), replace() or replaceAll()
        // in CKEditor. The second parameter (optional), is the path for the
        // CKFinder installation (default = "/ckfinder/").
        CKFinder::SetupCKEditor( $ckeditor, '/ckfinder/' ) ;

        $ckeditor->editor('editor1', $nDetails);
    }

    ?></p>

回答1:


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

Where editor1 is the id of your CKEDITOR field




回答2:


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.




回答3:


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.




回答4:


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
}); 


来源:https://stackoverflow.com/questions/7757006/how-to-clear-ckeditor-with-jquery

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!