【问题标题】:How to add custom buttons to Summernote toolbar如何将自定义按钮添加到 Summernote 工具栏
【发布时间】:2020-12-11 07:51:09
【问题描述】:

还有其他人对此有疑问吗?我关注了文档,但按钮没有显示。它只是创建一个空的 div。控制台没有错误。

文档:https://summernote.org/deep-dive/#custom-button

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
    }   
});

渲染的 HTML

【问题讨论】:

  • 谢谢你,其实我错过了`工具栏:[['mybutton', ['hello']]],`

标签: javascript summernote


【解决方案1】:

我想通了。所以我不得不把 HelloButton 函数放在 $(document).ready() 之外

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-01-05
    • 1970-01-01
    • 2015-05-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多