jQuery Summernote - Get text back into editor

前端 未结 6 979
鱼传尺愫
鱼传尺愫 2021-01-01 12:39

I got problems getting text back into the summernote editor.

I already tried (but did not work):

$(\"#EDITsummernote\").innerHtml = \'test\';
         


        
相关标签:
6条回答
  • 2021-01-01 13:01

    Insert Text:

    $('#summernote').summernote('editor.insertText', 'hello world');
    

    You can use this line if you want to set (paste) HTML code in editor:

    $('#summernote').summernote('editor.pasteHTML', '<b>hello world</b>');
    

    Source code

    Bonus

    Clear all editor content:

    $('#summernote').code("");
    
    0 讨论(0)
  • 2021-01-01 13:02

    None of the Solutions works for me until I did this.

    <textarea name="description" class="form-control summernote_rpt summernote_custom"></textarea>

    Let's say you have initialized summernote something like this in which I have two classes .summernote_custom was used $('.summernote_rpt').summernote(options);

    when the entire page loads and when I wanted to update the summernote value using js I used $('.summernote_rpt').summernote('code','data');

    0 讨论(0)
  • 2021-01-01 13:06

    $(".summernote").code("your text");

    0 讨论(0)
  • 2021-01-01 13:09

    To set:

    $('#summernote').summernote('code', '<b> hello world </b>');
    

    To get:

    var get_code = $('#summernote').summernote('code');
    

    Documentation: http://summernote.org/getting-started/#get--set-code

    0 讨论(0)
  • 2021-01-01 13:12

    Since v0.7.0 code() has been deprecated and removed (same story for destroy() method).

    You must use $(".summernote").summernote("code", "your text");

    Reference: https://summernote.org/getting-started/#get--set-code

    After v0.7.0, direct jquery methods, destroy and code were removed for avoiding conflict with other jquery libraries. You can call this methods with summernote api.

    0 讨论(0)
  • 2021-01-01 13:24

    To set text in the summernote editor:

    $('#summernote').summernote('editor.insertText', 'hello world');
    
    0 讨论(0)
提交回复
热议问题