【问题标题】:How to clear ckeditor form after submitting with ajax?使用ajax提交后如何清除ckeditor表单?
【发布时间】:2011-07-23 11:51:42
【问题描述】:

我正在使用 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);
});   

我用的是clearForm: true,但是提交表单后,没有清除textarea Ckeditor的值。如何清除textarea ckeditor?

【问题讨论】:

  • 所以你要在提交权后清除fck

标签: jquery ajax forms ckeditor


【解决方案1】:

我使用函数 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);
}); 

【讨论】:

  • 如果您使用此代码解决了问题,请接受您自己的答案。否则,您是在对系统说它仍未解决。不要编辑说 SOLVED 虽然
【解决方案2】:

试试$("#comment-textarea").val(""); 之类的...它应该放在这里。

$('#formcomments').submit(function() {
        CKupdate();
$("#comment-textarea").val("");
    });

#comment-textarea 是您要清除的文本区域的 ID,.val(' ') 将其值设置为 ' ' - 注意 '; 之间的空格

【讨论】:

    【解决方案3】:

    只需创建实例并使用setHtml

    在提交中使用这个

    var Editor1 = FCKeditorAPI.GetInstance('comment-textarea'');
    Editor1.SetHTML();
    

    对于ckeditor

    设置数据

    http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.editor.html#setData

    【讨论】:

    • 这只是针对旧的 FCKeditor,他询问了具有不同 API 的 CKEditor。
    【解决方案4】:

    我使用了这两种方法并为我工作

    $(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('');
        }
    });
    

    希望对你有帮助

    【讨论】:

      【解决方案5】:
      CKEDITOR.instances.msg.setData(''); 
      

      【讨论】:

      • 与近十年前的the accepted answer 所建议的CKEDITOR.instances[instance].setData(''); 相比,使用这种方法有什么好处?
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-12-03
      • 2018-09-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-22
      • 2012-01-31
      相关资源
      最近更新 更多