How can i get content of CKEditor using JQuery?

前端 未结 15 1796
甜味超标
甜味超标 2020-12-04 15:21

I\'m using CKEditor. I am saving the form values with ajax using page methods.

But the content of CKEditor value cannot be saving into the table.

I dont post

相关标签:
15条回答
  • 2020-12-04 15:49

    To get data of ckeditor, you need to get ckeditor instance

    HTML code:

    <textarea class="form-control" id="reply_mail_msg" name="message" rows="3" data-form-field="Message" placeholder="" autofocus="" style="display: none;"></textarea>
    

    Javascript:

    var ck_ed = CKEDITOR.instances.reply_mail_msg.getData();
    
    0 讨论(0)
  • 2020-12-04 15:54

    If you don't hold a reference to the editor, as in Aeon's answer, you can also use the form:

    var value = CKEDITOR.instances['my-editor'].getData();
    
    0 讨论(0)
  • 2020-12-04 15:57

    Now that jQuery adapter exists, this answer needs to be updated:

    Say you initiated the editor with $('.ckeditor').ckeditor(opt) then you get the value with $('.ckeditor').val()

    0 讨论(0)
  • 2020-12-04 15:57

    you can retreive data like this :

    <script>
    var data = CKEDITOR.instances.editor1.getData();
    // Your code to save "data", usually through Ajax.
    </script>
    

    reference : http://docs.ckeditor.com/#!/guide/dev_savedata

    0 讨论(0)
  • 2020-12-04 15:57

    Easy way to get the text inside of the editor or the length of it :)

     var editorText = CKEDITOR.instances['<%= your_editor.ClientID %>'].getData();
     alert(editorText);
    
     var editorTextLength = CKEDITOR.instances['<%= your_editor.ClientID %>'].getData().length;
     alert(editorTextLength);
    
    0 讨论(0)
  • 2020-12-04 15:58

    First of all you should include ckeditor and jquery connector script in your page,

    then create a textarea

    <textarea name="content" class="editor" id="ms_editor"></textarea>
    

    attach ckeditor to the text area, in my project I use something like this:

    $('textarea.editor').ckeditor(function() {
            }, { toolbar : [
                ['Cut','Copy','Paste','PasteText','PasteFromWord','-','Print', 'SpellChecker', 'Scayt'],
                ['Undo','Redo'],
                ['Bold','Italic','Underline','Strike','-','Subscript','Superscript'],
                ['NumberedList','BulletedList','-','Outdent','Indent','Blockquote'],
                ['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'],
                ['Link','Unlink','Anchor', 'Image', 'Smiley'],
                ['Table','HorizontalRule','SpecialChar'],
                ['Styles','BGColor']
            ], toolbarCanCollapse:false, height: '300px', scayt_sLang: 'pt_PT', uiColor : '#EBEBEB' } );
    

    on submit get the content using:

    var content = $( 'textarea.editor' ).val();
    

    That's it! :)

    0 讨论(0)
提交回复
热议问题