[英]How to add custom buttons to Summernote toolbar
Anyone else having problems with this?还有其他人对此有疑问吗? I followed the docs but the button is not showing up.我按照文档进行操作,但未显示该按钮。 It just creates an empty div.它只是创建一个空的 div。 No errors in console.控制台中没有错误。
Docs: https://summernote.org/deep-dive/#custom-button文档: https://summernote.org/deep-dive/#custom-button
JS JS
$(document).ready(function() {
$('#summernote').summernote({
toolbar: [
['mybutton', ['hello']]
],
buttons: {
hello: HelloButton
}
});
var HelloButton = function (context) {
var ui = $.summernote.ui;
// create button
var button = ui.button({
contents: '<i class="fa fa-child"/> Hello',
tooltip: 'hello',
click: function () {
// invoke insertText method with 'hello' on editor module.
context.invoke('editor.insertText', 'hello');
}
});
return button.render(); // return button as jquery object
}
});
Rendered HTML呈现 HTML
I figured it out.我想到了。 So I had to put the HelloButton function outside of $(document).ready()所以我不得不将 HelloButton function 放在 $(document).ready() 之外
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.