SummerNote insertHtml

前端 未结 5 2007
攒了一身酷
攒了一身酷 2021-02-19 07:43

I have a \'template\' selector, that enables people to change the \'text/html\' of the current textarea.

So when they change templates, I need to update the Summernote H

相关标签:
5条回答
  • 2021-02-19 08:22

    This works best for me

    var html = '<h2>Hello World!!</h2>'; $('#divID').summernote('code', html);

    0 讨论(0)
  • 2021-02-19 08:30

    If you don't want to replace all the content from the note, you can use the insertHTML command from the execCommand WebAPI.

    As summernote is based on the execCommand WebAPI, we can use directly its resources. So the most simple way to add a HTML content to the summernote can be using the insertHtml parameter like this:

    document.execCommand('insertHtml', null, '<p>My text <span style="color:red;">here</span></p>');
    
    0 讨论(0)
  • 2021-02-19 08:31
    .summernote('pasteHTML', '<b>inserted html</b> ');
    
    0 讨论(0)
  • 2021-02-19 08:36

    According to the api (https://summernote.org/getting-started/#get--set-code),

    to change wysiwyg's value you should use summernote function with 'code' string as first parameter and your content as second one

    Like this :

    $('.dialogMessageArea').summernote('code', data.results[0].template);
    
    0 讨论(0)
  • 2021-02-19 08:36

    This should actually work

    $('.dialogMessageArea').code('some value you want'); 
    

    NOTE:

    HTML inside code() function has to be a string. I don't think it will work if you are trying to insert an invalid HTML contents.

    Try doing this:

    Create a hidden div and then in your AJAX success method try to insert the datas from the AJAX and then retrieve it using jquery's text() function.

    <div style="display:none;" id="hidden_div">
    
    
                success: function (data) {
                    $('.subjectMessage').val(data.results[0].subject);
                    if(data.results[0].template) {
                        $('#hidden_div').html(data.results[0].template);
                        $('.dialogMessageArea').code($('#hidden_div').text());
                    }
                },
    
    0 讨论(0)
提交回复
热议问题