jQuery 如何使用jquery清除ckeditor
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7757006/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how to clear ckeditor with jquery
提问by user875293
How can i clear the ckeditor textarea with jquery at the click of a button/link?
如何在单击按钮/链接时使用 jquery 清除 ckeditor textarea?
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
我曾尝试这样的:$("textarea.editor").val('');
和$("textarea.editor1").val('');
我试图与1末,因为这条线的初始化编辑器时,$ckeditor->editor('editor1', $nDetails);
在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>
回答by ghostCoder
CKEDITOR.instances.editor1.setData('');
CKEDITOR.instances.editor1.setData('');
Where editor1 is the id of your CKEDITOR field
其中 editor1 是您的 CKEDITOR 字段的 ID
回答by Aarthi
The below code clears the value in the ckeditor textarea. This will works 4.4 version also.
下面的代码清除 ckeditor textarea 中的值。这也适用于 4.4 版本。
CKEDITOR.instances['content'].setData('');
Content is the id of the particular text-area.
内容是特定文本区域的 ID。
回答by Govinda Rajbhar
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.
CKupdate()
当您想清除 CKEditor 文本时调用函数。
回答by Oleg
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.
在我的代码中,我必须以编程方式更改 ckeditor 中的文本,但直到我做了延迟集它才起作用。这可能会有所帮助。
_.defer(function () {
it._controls.wysiwyg.setData(bodyText); // by the direct reference
//CKEDITOR.instances.editor1.setData(''); // or this way like in the example
});