weixin_33701294 2016-04-24 07:26 采纳率: 0%
浏览 48

ajax格式的CKEditor

I try to use the same ckeditor replace several time in a ajax form:

 ... <textarea id="textareaId"></textarea> ...

And a javascript code

CKEDITOR.replace('textareaId');
$('#textareaId').val("first");
CKEDITOR.replace('textareaId');
$('#textareaId').val("second");

Can somepody know why id does not show "second" instead of "first" in the textarea with ckeditor? And how to get the correct value $('#textareaId').val()? Thank you

  • 写回答

2条回答 默认 最新

  • weixin_33735077 2016-04-24 07:33
    关注

    Ids should be unique, so (I don't use CKEditor btw so no clue what this is trying to achieve but am explaining how ids should be used):

    <textarea id="textareaId"></textarea>
    <textarea id="textareaId2"></textarea> <!-- changed id -->
    
    CKEDITOR.replace('textareaId');
    $('#textareaId').val("first");
    CKEDITOR.replace('textareaId2'); /* new id for text area */
    $('#textareaId2').val("second");
    
    评论

报告相同问题?