как очистить ckeditor с помощью jquery - PullRequest
11 голосов
/ 13 октября 2011

Как я могу очистить текстовое поле ckeditor с помощью jquery одним нажатием кнопки / ссылки?

Я пробовал это: $("textarea.editor").val(''); и $("textarea.editor1").val(''); Я пытался с 1 в конце из-за этогострока при инициализации редактора $ckeditor->editor('editor1', $nDetails); в PHP

Любая помощь будет принята с благодарностью.

<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>

Ответы [ 4 ]

44 голосов
/ 14 октября 2011

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

Где editor1 - идентификатор вашего поля CKEDITOR

15 голосов
/ 28 июля 2014

Приведенный ниже код очищает значение в текстовой области ckeditor.Это будет работать и в версии 4.4.

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

Контент - это идентификатор конкретной текстовой области.

1 голос
/ 20 июня 2015

Попробуйте, это может быть полезно.

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

Вызовите функцию CKupdate(), когда вы хотите очистить текст CKEditor.

0 голосов
/ 06 августа 2018

В моем коде мне пришлось программно изменить текст в ckeditor, но он не работал, пока я не сделал защищенный набор.Это может быть полезно.

_.defer(function () {
    it._controls.wysiwyg.setData(bodyText); // by the direct reference
    //CKEDITOR.instances.editor1.setData(''); // or this way like in the example
}); 
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...