gpt4 book ai didi

javascript - SummerNote insertHtml

转载 作者:技术小花猫 更新时间:2023-10-29 12:28:27 26 4
gpt4 key购买 nike

我有一个"template"选择器,可以让人们更改当前文本区域的“文本/html”。

所以当他们更改模板时,我需要更新 Summernote HTML。我看到了 (insertText) 的方法,但它不适用于 HTML。

有HTML版本的解决方案吗?

我认为有一个 .code() 解决方案,但似乎不起作用?我收到错误消息“不是函数”

如有任何帮助,我们将不胜感激!

$('.dialogMessageArea').summernote({
height:'230px',
focus:true,
toolbar: [
['style', ['bold', 'italic', 'underline', 'clear']],
['fontsize', ['fontsize']],
['para', ['ul', 'ol', 'paragraph']],
['table', ['table']],
['misc', ['fullscreen','undo','redo']]
]
});

$(document).on('change', '.messageTemplate', function() {
var templateId = $(this).selected().attr('value');
if(templateId) {
$.ajax({
type: "POST",
dataType: "json",
url: '/cont/templates/GetTemplate',
data: {'templateId': templateId},
success: function (data) {
$('.subjectMessage').val(data.results[0].subject);
if(data.results[0].template) {
$('.dialogMessageArea').code(data.results[0].template);
}
},
error: function () {
alert('We were not able to get your template');
}
});
}
});

console.log($('.dialogMessageArea'));
console.log("<b>Welcome</b><h3>hello world</h3>");

enter image description here

最佳答案

根据 api ( https://summernote.org/getting-started/#get--set-code ),

要更改所见即所得的值,您应该使用 summernote 函数,其中“代码”字符串作为第一个参数,您的内容作为第二个参数

像这样:

$('.dialogMessageArea').summernote('code', data.results[0].template);

关于javascript - SummerNote insertHtml,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34170950/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com