【问题标题】:How to change value in attribute title for button on the toolbar tinymce?如何更改工具栏tinymce上按钮的属性标题值?
【发布时间】:2021-10-26 12:15:39
【问题描述】:

我需要为元素“Supersctipt”设置属性标题值为“footnote”。
默认情况下,此处为“上标”。
我不知道该怎么做。这是我的代码tinymce:

initTinyMCE()
function initTinyMCE(selector = '.js-tinymce') {
    tinymce.init({
        selector: selector,
        skin: false,
        branding: false,
        menubar: false,
        height: 500,
        toolbar:
            'undo redo | formatselect | bold italic underline superscript | bullist numlist | removeformat code',
        plugins: [
            "code", "paste", "lists"
        ],
        paste_as_text: true,
        block_formats: 'Paragraph=p; Header 3=h3; Header 4=h4; Header 5=h5; Header Underline=h6; ',
        content_css: '/css/tinymce.css?' + new Date().getTime(),
    })
}

我尝试通过 jQuery 引用这个元素,但没有成功,因为 tinymce 稍后会启动:

$(function() {
   $('.js-tinymce button[title="Superscript"]').attr('aria-label', 'footnote')
})

我也试过这种方式,阅读文档:

formats: {
            sup: { selector: 'sup'},
          },
style_formats: [
            { title: 'footnote', format: 'sup' },
          ]

但也没有成功(最后,这个简单的任务怎么做?

【问题讨论】:

  • @ikhvjs ,是的,我查看并尝试过:style_formats: [{title: 'footnote', inline: 'superscript'}] 但它不起作用.我做错了什么?
  • 我仔细检查了文档,似乎无法从 TinyMCE 解决方案更改按钮名称的内容。它只更新自定义格式部分。
  • @ikhvjs 听起来很悲伤
  • @ikhvjs,我找到了解决方案,并在下面发布了答案。感谢您的帮助。

标签: javascript jquery tinymce tinymce-5


【解决方案1】:

耶耶!我通过在tinymce init 对象的末尾添加setup:... 选项解决了这个问题。代码:

initTinyMCE()
function initTinyMCE(selector = '.js-tinymce') {
    tinymce.init({
        selector: selector,
        skin: false,
        branding: false,
        menubar: false,
        height: 500,
        toolbar:
            'undo redo | formatselect | bold italic underline superscript | bullist numlist | removeformat code',
        plugins: [
            "code", "paste", "lists"
        ],
        paste_as_text: true,
        block_formats: 'Paragraph=p; Header 3=h3; Header 4=h4; Header 5=h5; Header Underline=h6',
        content_css: '/css/tinymce.css?' + new Date().getTime(),
        setup: function(tinyMCE) {
            tinyMCE.on('init', function() {
                $('[aria-label="Superscript"]').attr('title', 'Footnote')
            });
        },
    })
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-06-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-29
    相关资源
    最近更新 更多