2014-07-13 48 views
0

我想每次點擊鏈接添加,添加CKEditor。我的代碼添加CKEditor第一次點擊。什麼可以做到所有點擊?在jquery上添加多個編輯器

:​​

HTML:

<script type="text/javascript" src="http://cdn.ckeditor.com/4.4.2/standard-all/ckeditor.js"></script> 
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script> 


<a class="add" href="#"><span class="icon-caret-right"></span>Add</a> 
<div class="000" style="width: 400px;height: 100px;"> 
</div> 

JS:

$(document).on('click', 'a.add', function (e) { 
    e.preventDefault(); 
    $('.000').append('<textarea class="ckeditor" name="description_ser" id="des"></textarea>'); 
$('.ckeditor').each(function(){ 
    CKEDITOR.replace($(this).attr('id')); 
}); 

})

回答

0

你不能有相同ID的多個元素(des在你的情況)在文件中。嘗試類似:

i=1; 
$(document).on('click', 'a.add', function (e) { 
    e.preventDefault(); 
    $('.000').append('<textarea class="ckeditor" name="description_ser" id="des-'+i+'"></textarea>'); 
    CKEDITOR.replace('des-'+i); 
    i++; 
}) 
相關問題