Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/86.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在页面上克隆或添加多个ck编辑器_Javascript_Jquery - Fatal编程技术网

Javascript 如何在页面上克隆或添加多个ck编辑器

Javascript 如何在页面上克隆或添加多个ck编辑器,javascript,jquery,Javascript,Jquery,我想要多个textarea(ck编辑器),用户可以在其中输入多个数据,我尝试了jquery的各种功能和方法,如clone()和appendTo,但问题是他们正在克隆textarea,但ckeditor不起作用,克隆了textarea后,我无法在其中写入任何内容 请帮帮我 这就是我试过的 测试1 测试2 谢谢为每个新文本区域添加一个id,并使用 CKEditor.replace(id[,config]) 比如: $(add_button).click(function(e){ //on add

我想要多个
textarea
(ck编辑器),用户可以在其中输入多个数据,我尝试了jquery的各种功能和方法,如
clone()
appendTo
,但问题是他们正在克隆
textarea
,但ckeditor不起作用,克隆了
textarea
后,我无法在其中写入任何内容 请帮帮我

这就是我试过的

测试1

测试2


谢谢

为每个新文本区域添加一个
id
,并使用
CKEditor.replace(id[,config])

比如:

$(add_button).click(function(e){ //on add input button click
        e.preventDefault();
        if(x < max_fields){ //max input box allowed
            x++; //text box increment
            var editorId = 'editor_' + x;
            $(wrapper).append('<div> <textarea id="'+editorId+'" class="ckeditor" name="ck[]"></textarea><a href="#" class="remove_field">Remove</a></div>'); //add input box

            CKEDITOR.replace(editorId, { height: 200 });
        }
    });
$(添加按钮)。单击(函数(e){//在添加输入按钮上单击
e、 预防默认值();
如果(x

向每个新文本区域添加一个
id
,并使用手动初始化编辑器
CKEditor.replace(id[,config])

比如:

$(add_button).click(function(e){ //on add input button click
        e.preventDefault();
        if(x < max_fields){ //max input box allowed
            x++; //text box increment
            var editorId = 'editor_' + x;
            $(wrapper).append('<div> <textarea id="'+editorId+'" class="ckeditor" name="ck[]"></textarea><a href="#" class="remove_field">Remove</a></div>'); //add input box

            CKEDITOR.replace(editorId, { height: 200 });
        }
    });
$(添加按钮)。单击(函数(e){//在添加输入按钮上单击
e、 预防默认值();
如果(x

检查此项以获取克隆编辑器

检查这把小提琴:


选项
行动
var REMOVE='';
var i=1;
$(文档).ready(函数(){
$('.add_more')。单击(函数(){
var oneplus=i+1;
var tr_object=$('tbody').find('tr:first').clone();
//按名称获取和重命名现有textarea。
$(tr_对象).find('textarea[name=“question_option_1”]”)。attr(“name”,“question_option_”+oneplus+”);
$(tr_对象).find('input').val('');
$(tr_object.find('td:last').html(“”);
$('tbody').append(tr_对象);
//替换代码
CKEDITOR.replace(“问题选项+oneplus+”);
//当我在测试期间单击AddMore时,额外的cke编辑器id也会附加到DOM中
//包括以下代码
$('cke#question_option_1')。每个(函数(){
var$ids=$('[id='+this.id+']');
如果($ids.length>1){
$ids.not(“:first”).remove();
}
});
i=i+1;
oneplus++;
});
$(文档)。在('单击','上。删除更多',函数(){
var id=$(this.nexist('tr').find('.id').val();
如果(id!=''){
如果(删除!=''){
移除=移除+','+id;
}否则{
移除=id;
}
$('#id').val(删除);
}
$(this).closest('tr').remove();
});
});

请检查此选项以获取克隆编辑器

检查这把小提琴:


选项
行动
var REMOVE='';
var i=1;
$(文档).ready(函数(){
$('.add_more')。单击(函数(){
var oneplus=i+1;
var tr_object=$('tbody').find('tr:first').clone();
//按名称获取和重命名现有textarea。
$(tr_对象).find('textarea[name=“question_option_1”]”)。attr(“name”,“question_option_”+oneplus+”);
$(tr_对象).find('input').val('');
$(tr_object.find('td:last').html(“”);
$('tbody').append(tr_对象);
//替换代码
CKEDITOR.replace(“问题选项+oneplus+”);
//当我在测试期间单击AddMore时,额外的cke编辑器id也会附加到DOM中
//包括以下代码
$('#ck