将自定义格式移动到tinymce中的工具栏



我的格式下拉列表中有自定义格式,效果很好。如何将此格式作为按钮添加到工具栏?

我的自定义格式看起来像

custom_caption: {title: 'image caption', inline: 'span', classes: 'caption'}

我试图添加到

toolbar: 'someb_default_buttons | custom_caption'

但不起作用

我做错了什么?

你可以这样做:

tinymce.init({
    selector: "textarea",
    toolbar: "customFormat",
    setup: function(editor) {
        editor.addButton('customFormat', {
            text: 'My custom formatting',
            icon: false,
            onclick: function() {
                // Add the custom formatting
                editor.formatter.toggle('custom_caption');
            }
        });
    }
});

更新

看看这个小提琴

我想这就是你想要的。用这个小提琴,你可以选择一些文本,点击My Custom Formatting按钮,文本将被<span class="caption">包围。

最新更新