【发布时间】:2016-03-14 06:17:33
【问题描述】:
我有一个“模板”选择器,可以让人们更改当前文本区域的“文本/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>");
【问题讨论】:
-
而不是
.code,试试.htmlapi.jquery.com/html -
是的,我确实尝试过。它什么也没做……还有其他想法吗?
-
确保
$('.dialogMessageArea')返回一个元素,并确保data.results[0].template包含有效的html? -
刚刚测试过,还是什么都没有……用截图更新了问题。
标签: javascript jquery html summernote