使用CKEditor的最初提交无法获取多行文本形式的价值,但它适用于第二次提交

问题描述 投票:0回答:2

我用CKEditor textarea的是参与而形成的区域。我需要的表单数据使用serializeArray() jQuery函数提交。起初提交,则返回值'。之后第二提交,它返回正确的值。我注意到,textarea的值不更新第一次但第二次。

$("form").submit(function(e){
        e.preventDefault();

        // not sure if you wanted this, but I thought I'd add it.
        // get an associative array of just the values.
        var values = $(this).serializeArray();

        var datas = {};
        values.forEach(element => {
            datas[element['name']] = element['value'].replace(/<[^>]+>/g, '');
        });
});
jquery ajax ckeditor
2个回答
0
投票

请参阅:https://ckeditor.com/docs/ckeditor4/latest/guide/dev_jquery.htmlhttps://ckeditor.com/docs/ckeditor4/latest/api/CKEDITOR_Adapters_jQuery.html#method-val

CKEditor的有jQuery的适配器,它允许你同时使用,编辑内部API以及jQuery方法。为了从HTML编辑器,请使用:

$( '#editor1' ).val( )

0
投票

CKEDITOR是jQuery库,所以你应该使用下面的代码获得它的值

var desc = CKEDITOR.instances['DSC'].getData();

或者,如果你实例已经然后定义就可以得到价值如下。

var editor = CKEDITOR.replace('editor');
alert(editor.getData());

在检查工作https://codepen.io/rohitmittal/pen/jdYXGe例如

你应该得到的形式连载,而不是CKEditor的所有表单字段的值。如果在获得第二次价值,我认为它会显示最后一次更新的值。如果更新值第二次,它仍然会显示你最近没有更新的最后一个值。所以,我更喜欢使用上面提到的语法来获得的CKEditor值并补充说,在形式上序列化阵列。

© www.soinside.com 2019 - 2024. All rights reserved.