Jquery 具有相同textarea名称的多个ckeditor实例
我正在努力添加多个ckeditor,点击添加更多按钮…我正在使用jquery加载一个表单,点击添加更多按钮…表单有五个字段,其中一个是描述,我想用文本编辑器替换textarea。 只有第一个ckeditor正在工作…出现在“添加更多”中的ckeditor不工作。 下面是html代码Jquery 具有相同textarea名称的多个ckeditor实例,jquery,ckeditor,Jquery,Ckeditor,我正在努力添加多个ckeditor,点击添加更多按钮…我正在使用jquery加载一个表单,点击添加更多按钮…表单有五个字段,其中一个是描述,我想用文本编辑器替换textarea。 只有第一个ckeditor正在工作…出现在“添加更多”中的ckeditor不工作。 下面是html代码 <div class="hid" id="multi_job_example"> <div class="a-header"> <div
<div class="hid" id="multi_job_example">
<div class="a-header">
<div class="fright"><a href="#" class="delete_job">Remove job</a></div>
<div class="slide"><ins class="i-o"></ins></div>
<div class="text"></div>
</div>
<div class="a-block my-form" id="input1">
<div class="form-group">
<label class="col-sm-3 control-label">Email Address:</label>
<div class="col-sm-5"><input type="text" name="ind_email[]" value="" id="email1" class="form-control"/></div>
</div>
<div class="form-group">
<label class="col-lg-3 control-label">Job Description: </label>
<div class="col-lg-7">
<textarea class="ckeditor" name="fe_description[]"></textarea>
</div>
</div>
</div>
</div>
<ul id="more_job_list" class="a-list">
</ul>
<div class="b">
<a href="#" id="add_job_link" class="btn-link"><ins class="with-icon i-list-add"></ins>Add more job</a>
</div>
</div>
<script type="text/javascript" src="{$site_root}application/modules/controller/js/ckeditor/ckeditor.js"></script>
<script type="text/javascript" src="{$site_root}application/modules/mycontroller/js/add_multi.js"></script>
<script type="text/javascript">
$(function(){
new addMultiJob({
counter: '',
addLinkId: 'add_job_link',
liListId: 'more_job_list',
liIdPrefix: 'job_li_',
exampleId: 'multi_job_example',
deleteSelector: 'a.delete_job'
});
});
</script>
电邮地址:
职位描述:
$(函数(){
新addMultiJob({
计数器:“”,
addLinkId:“添加作业链接”,
liListId:“更多工作列表”,
liIdPrefix:“工作”,
exampleId:“多重作业”示例,
deleteSelector:“a.delete\u作业”
});
});
下面是在add_multi_job.js文件中添加更多字段的jquery代码
function addMultiJob(optionArr){
this.properties = {
counter: 0,
addLinkId: 'add_job_link',
liListId: 'more_job_list',
liIdPrefix: 'job_li_',
exampleId: 'multi_job_example',
deleteSelector: 'a.delete_job',
headerSelector: 'input.ext_org',
changed: false
}
var _self = this;
this.Init = function(options){
_self.properties = $.extend(_self.properties, options);
_self.properties.counter = parseInt(_self.properties.counter);
$('#'+_self.properties.addLinkId).bind('click', function(){
var content = $('#'+_self.properties.exampleId).html();
_self.properties.counter++;
content = content.replace(/__NUM__/g, _self.properties.counter);
$('#'+_self.properties.liListId)
.append('<li id="'+_self.properties.liIdPrefix+_self.properties.counter+'">'+content+'</li>');
return false;
});
$('#'+_self.properties.liListId+' '+_self.properties.deleteSelector).live('click', function(){
$(this).parent().parent().parent().remove();
return false;
});
$('#'+_self.properties.liListId+' '+_self.properties.headerSelector).live('keyup', function(){
$(this).parent().parent().parent().parent().find('.a-header .text').html($('<div/>').text($(this).val()).html());
});
$('#'+_self.properties.liListId+' .a-header .slide').live('click', function(){
if($(this).find('ins').hasClass('i-o')){
$(this).find('ins').removeClass('i-o').addClass('i-c');
$(this).parent().parent().find('.a-block').slideUp();
}else{
$(this).find('ins').removeClass('i-c').addClass('i-o');
$(this).parent().parent().find('.a-block').slideDown();
}
});
}
_self.Init(optionArr);
}
函数添加多工单(optionArr){
此属性={
柜台:0,,
addLinkId:“添加作业链接”,
liListId:“更多工作列表”,
liIdPrefix:“工作”,
exampleId:“多重作业”示例,
deleteSelector:'a.delete_job',
headerSelector:'input.ext_org',
更改:false
}
var _self=这个;
this.Init=函数(选项){
_self.properties=$.extend(_self.properties,options);
_self.properties.counter=parseInt(_self.properties.counter);
$('#'+_self.properties.addLinkId.bind('click',function()){
var content=$('#'+_self.properties.exampleId.html();
_self.properties.counter++;
content=content.replace(/\uuu NUM\uuu/g,\u self.properties.counter);
$('#'+_self.properties.liListId)
.append(““+content+” ”);
返回false;
});
$('#'+_self.properties.liListId+''+_self.properties.deleteSelector.live('click',function()){
$(this.parent().parent().parent().remove();
返回false;
});
$('#'+_self.properties.liListId++''+_self.properties.headerSelector.live('keyup',function()){
$(this.parent().parent().parent().parent().find('.a-header.text').html($('').text($(this.val()).html());
});
$('#'+_self.properties.liListId+'.a-header.slide').live('click',function(){
if($(this).find('ins').hasClass('i-o')){
$(this).find('ins').removeClass('i-o').addClass('i-c');
$(this.parent().parent().find('.a-block').slideUp();
}否则{
$(this).find('ins').removeClass('i-c').addClass('i-o');
$(this.parent().parent().find('.a-block').slideDown();
}
});
}
_self.Init(optionArr);
}
我正在使用ckeditor 4.4.6
仅在我的视图文件中包含来自ckeditor插件的js文件问题在于,通过添加更多选项添加textarea后,您必须启动(重新初始化)ck编辑器。因为前一个编辑器不适用于动态内容加载。你的意思是我必须先销毁前一个编辑器,然后再加载新编辑器…?不,你只需再次启动它。使用一些新元素(如class/id等)甚至你也可以用textarea标记再次启动它。它只会告诉ck编辑器在某些动态内容上再次加载。可能是重复的