jQuery 使用ajax提交后如何清除ckeditor表单?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5442646/
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 form after submitting with ajax?
提问by serg66
I am using CKeditor, Jquery and plugin jquery form.
我正在使用 CKeditor、Jquery 和插件 jquery 表单。
CKEDITOR.replace( 'comment-textarea' );
function CKupdate(){
for ( instance in CKEDITOR.instances )
CKEDITOR.instances[instance].updateElement();
}
$(document).ready(function(){
var options = {
success: function (html) {
$('#comments').append(html);
},
clearForm: true
};
$('#formcomments').submit(function() {
CKupdate();
});
$('#formcomments').ajaxForm(options);
});
I am using clearForm: true, But after submiting a form, value of the textarea Ckeditor is not cleared. How to clear the textarea ckeditor?
我正在使用clearForm: true,但是在提交表单后,不会清除 textarea Ckeditor 的值。如何清除textarea ckeditor?
回答by serg66
Thanks all, I use function setData and all works fine:
谢谢大家,我使用函数 setData 并且一切正常:
function CKupdate(){
for ( instance in CKEDITOR.instances ){
CKEDITOR.instances[instance].updateElement();
CKEDITOR.instances[instance].setData('');
}
}
$(document).ready(function(){
CKEDITOR.replace( 'comment-textarea' );
var options = {
success: function (html) {
$('#comments').append(html);
},
clearForm: true
};
$('#formcomments').submit(function() {
CKupdate();
});
$('#formcomments').ajaxForm(options);
});
回答by George I
Try something like $("#comment-textarea").val(""); ... it shoulf go here .
尝试类似 $("#comment-textarea").val(""); ......它应该去这里。
$('#formcomments').submit(function() {
CKupdate();
$("#comment-textarea").val("");
});
#comment-textarea is the id of the textarea you want to clearand .val(' ') sets it's value to ' ' - notice the space between the ';
#comment-textarea 是您要清除的文本区域的 ID,.val(' ') 将其值设置为 ' ' - 注意 '; 之间的空格;
回答by Gowri
simple create instance and use setHtml
简单的创建实例和使用 setHtml
use this inside submit
在提交中使用这个
var Editor1 = FCKeditorAPI.GetInstance('comment-textarea'');
Editor1.SetHTML();
for ckeditor
对于 ckeditor
setData
设置数据
http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.editor.html#setData
http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.editor.html#setData
回答by Amdadol Haque
I used this two method and worked for me
我使用了这两种方法并为我工作
$(window).load(function(e) {
for ( instance in CKEDITOR.instances ){
CKEDITOR.instances[instance].updateElement();
}
CKEDITOR.instances[instance].setData('');
});
//OR
$.ajax({
type:'POST',
url:'response.php',
data: data,
cache:false,
success: function(e)
{
for ( instance in CKEDITOR.instances ){
CKEDITOR.instances[instance].updateElement();
}
CKEDITOR.instances[instance].setData('');
}
});
Hope It helps
希望能帮助到你
回答by Amit Dave
CKEDITOR.instances.msg.setData('');
CKEDITOR.instances.msg.setData('');