【问题标题】:How to add a custom button to add text to tinymce editor如何添加自定义按钮以将文本添加到 tinymce 编辑器
【发布时间】:2013-08-16 13:45:01
【问题描述】:

我想要 tinymce 工具栏中的按钮。单击该按钮时,无论光标在哪里,“HELLO”都应该出现在编辑器中。

版本:3.3.7

但我无法添加该按钮。

我试过添加这样的按钮

setup: function (ed) {
    ed.addButton('example', {
         title : 'example.desc',
         image : '../jscripts/tiny_mce/plugins/example/img/example.gif',
         onclick : function() {
            ed.windowManager.alert('Hello world!! Selection: ' + ed.selection.getContent({format : 'text'}));
         }
      });
    }

【问题讨论】:

    标签: tinymce


    【解决方案1】:

    尝试关注这个fiddle

    希望对你有帮助!!

    注意:我使用的是 3.4.8 版本

    代码镜像:

    <script type="text/javascript">
    tinyMCE.init({
        // General options
        mode : "textareas",
        theme : "advanced",
        plugins : "autolink,lists,spellchecker,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,imagemanager,filemanager",
    
        // Theme options
        theme_advanced_buttons1 : "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,styleselect,formatselect,fontselect,fontsizeselect",
        theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
        theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen",
        theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,spellchecker,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,blockquote,pagebreak,|,insertfile,insertimage,example",
        theme_advanced_toolbar_location : "top",
        theme_advanced_toolbar_align : "left",
        theme_advanced_statusbar_location : "bottom",
        theme_advanced_resizing : true,
        width: "100%",
        height: "400",
        setup: function (ed) {
        ed.addButton('example', {
             title : 'example.desc',
             image : './/',
             onclick : function() {
                tinyMCE.execCommand('mceInsertContent',false, 'Hello!!'); 
             }
          });
        }
    });
    </script>
    
    <form method="post" action="dump.php">
        <textarea name="content"></textarea>
    </form>
    

    【讨论】:

    • 如何获得选择器?
    【解决方案2】:

    初始化时不要忘记将按钮添加到toolbar 选项。

    http://fiddle.tinymce.com/ngdaab/0

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-05-02
      • 2012-11-24
      • 2017-11-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-11
      相关资源
      最近更新 更多