Jus*_*tin 13 html javascript jquery summernote
我有一个'模板'选择器,使人们可以更改当前textarea的'text/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');
}
});
}
});
Run Code Online (Sandbox Code Playgroud)
console.log($('.dialogMessageArea'));
console.log("<b>Welcome</b><h3>hello world</h3>");
Run Code Online (Sandbox Code Playgroud)
Poo*_*ooz 37
根据api(http://summernote.org/getting-started/#basic-api),
要改变wysiwyg的值,你应该使用summernote函数,将'code'字符串作为第一个参数,将你的内容作为第二个参数
像这样 :
$('.dialogMessageArea').summernote('code', data.results[0].template);
Run Code Online (Sandbox Code Playgroud)
小智 18
.summernote('pasteHTML', '<b>inserted html</b> ');
Run Code Online (Sandbox Code Playgroud)