如何用jquery清除ckeditor

时间:2011-10-13 16:02:21

标签: jquery ckeditor

如何通过点击按钮/链接清除带有jquery的ckeditor textarea?

我试过这个:$("textarea.editor").val('');$("textarea.editor1").val('');我在PHP中初始化编辑器$ckeditor->editor('editor1', $nDetails);时因为这一行而尝试使用1

非常感谢任何帮助。

<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 个答案:

答案 0 :(得分:42)

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

其中editor1是您的CKEDITOR字段的ID

答案 1 :(得分:14)

以下代码清除ckeditor textarea中的值。这也适用于4.4版本。

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

内容是特定文本区域的ID。

答案 2 :(得分:1)

尝试它可能有帮助。

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

当您要清除CKEditor文本时,请调用CKupdate()功能。

答案 3 :(得分:0)

在我的代码中,我不得不以编程方式更改ckeditor中的文本,但是直到我进行了延迟设置后,该文本才起作用。这可能会有所帮助。

_.defer(function () {
    it._controls.wysiwyg.setData(bodyText); // by the direct reference
    //CKEDITOR.instances.editor1.setData(''); // or this way like in the example
});