24

我想直接在工具栏(如 tinymce 版本 3)上更改标题(h1、h2、h3),因为我在创建新文章时非常使用它。我正在尝试在互联网上搜索,但没有找到任何答案。请帮我。非常感谢 在此处输入图像描述

4

4 回答 4

36

这个答案肯定迟到了,但也许它可以帮助像我这样的其他人,人们如何为同一个问题寻找答案。我在这里读到:http: //blog.ionelmc.ro/2013/10/17/tinymce-formatting-toolbar-buttons/

首先,您必须创建插件:

tinyMCE.PluginManager.add('stylebuttons', function(editor, url) {
  ['pre', 'p', 'code', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6'].forEach(function(name){
   editor.addButton("style-" + name, {
       tooltip: "Toggle " + name,
         text: name.toUpperCase(),
         onClick: function() { editor.execCommand('mceToggleFormat', false, name); },
         onPostRender: function() {
             var self = this, setup = function() {
                 editor.formatter.formatChanged(name, function(state) {
                     self.active(state);
                 });
             };
             editor.formatter ? setup() : editor.on('init', setup);
         }
     })
  });
});

然后在工具栏中使用它:

tinyMCE.init({
   selector: '#id',
   toolbar: "undo redo | style-p style-h1 style-h2 style-h3 style-pre style-code",
   plugins: "stylebuttons",
});
于 2014-01-27T15:46:31.217 回答
13
        tinymce.init({
            toolbar: 'undo redo | alignleft aligncenter alignright alignjustify | formatselect fontselect fontsizeselect | bullist numlist | outdent indent',
         });

这是在 TinyMCE 4 中将 H1、段落和其他选项添加到工具栏的更快方法。

有关完整列表,请参阅: http ://www.tinymce.com/wiki.php/Controls 特别是“核心”部分。这显示了最常用的工具。

于 2014-08-10T23:08:35.783 回答
10

使用以下对我有用

tinymce.init({
    toolbar: 'formatselect',
    block_formats: 'Paragraph=p;Heading 2=h2;Heading 3=h3;Heading 4=h4;',
});

编辑器将如下所示:

在此处输入图像描述

于 2018-01-30T16:29:18.243 回答
3

参考 TINYMCE 论坛上的这个问题:

http://www.tinymce.com/forum/viewtopic.php?id=32801

在配置中使用这些参数。

style_formats: [
            {title: 'Headers', items: [
                {title: 'h1', block: 'h1'},
                {title: 'h2', block: 'h2'},
                {title: 'h3', block: 'h3'},
                {title: 'h4', block: 'h4'},
                {title: 'h5', block: 'h5'},
                {title: 'h6', block: 'h6'}
            ]},

            {title: 'Inline', items: [
                {title: 'Bold', inline: 'b', icon: 'bold'},
                {title: 'Italic', inline: 'i', icon: 'italic'},
                {title: 'Underline', inline: 'span', styles : {textDecoration : 'underline'}, icon: 'underline'},
                {title: 'Strikethrough', inline: 'span', styles : {textDecoration : 'line-through'}, icon: 'strikethrough'},
                {title: 'Superscript', inline: 'sup', icon: 'superscript'},
                {title: 'Subscript', inline: 'sub', icon: 'subscript'},
                {title: 'Code', inline: 'code', icon: 'code'},
            ]},

            {title: 'Blocks', items: [
                {title: 'Paragraph', block: 'p'},
                {title: 'Blockquote', block: 'blockquote'},
                {title: 'Div', block: 'div'},
                {title: 'Pre', block: 'pre'}
            ]},

            {title: 'Alignment', items: [
                {title: 'Left', block: 'div', styles : {textAlign : 'left'}, icon: 'alignleft'},
                {title: 'Center', block: 'div', styles : {textAlign : 'center'}, icon: 'aligncenter'},
                {title: 'Right', block: 'div', styles : {textAlign : 'right'}, icon: 'alignright'},
                {title: 'Justify', block: 'div', styles : {textAlign : 'justify'}, icon: 'alignjustify'}
            ]}
        ]
于 2015-09-28T23:43:49.447 回答