javascript - 带有文字的 TinyMCE 自定义按钮

标签 javascript tinymce

有没有办法将自定义按钮添加到 TinyMCE 工具栏,上面只有文本(没有图像)? 尝试删除设置图像路径部分,现在它有一个空白按钮。这是我现有的代码:

<script language="javascript" type="text/javascript">
        tinyMCE.init({
            mode: "textareas",
            theme: "advanced",
            theme_advanced_buttons1: "bold,italic,underline,separator,strikethrough,justifyleft,justifycenter,justifyright, justifyfull,bullist,numlist,undo,redo,link,unlink",
            theme_advanced_buttons2: "mybutton",
            theme_advanced_buttons3: "",
            theme_advanced_toolbar_location: "top",
            theme_advanced_toolbar_align: "left",
            theme_advanced_statusbar_location: "bottom",
            setup: function (ed) {
                // Add a custom button
                ed.addButton('mybutton', {
                    title: 'My button',
                    onclick: function () {

                        ed.focus();
                        ed.selection.setContent('SampleText');
                    }
                });
            }
        });
</script>

如何在没有图片的按钮上设置文字?

最佳答案

只需将工具栏“mybutton”放入内部,然后将其添加到 tinymce.init 中:

setup: function(editor) {
editor.addButton('mybutton', {
                type: 'menubutton',
                text: 'My button',
                icon: false,
                menu: [
                    {text: 'Menu item 1', onclick: function() {editor.insertContent('Menu item 1');}},
                    {text: 'Menu item 2', onclick: function() {editor.insertContent('Menu item 2');}}
                ]
            });
        }   

关于javascript - 带有文字的 TinyMCE 自定义按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15103613/

相关文章:

javascript - 如果我在 textarea 中插入一个段落,如何设置 div 的不同位置

javascript - 用于扩展框的 float 箭头(jQuery)

html - 工具提示在 Tinymce 中的位置

tinymce - 如何在 TinyMCE 中覆盖 Ctrl+V

html - 减小 TinyMCE 文本区域中的行间距

css - 我可以使用 TinyMCE 格式配置为给定对齐的不同元素设置不同的类吗?

javascript - 如何在 contenteditable 元素中用 html 替换选定的文本?

Javascript,如何使用 DOM xpath 选择 <br> 标记之间的内容

javascript - 验证工资输入 jQuery

javascript - 初始化 Tinymce 的问题