5

我想要 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'}));
         }
      });
    }
4

2 回答 2

5

尝试跟随这个小提琴

希望能帮助到你!!

注意:我使用的是 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>
于 2013-08-20T06:58:32.753 回答
5

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

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

于 2015-08-09T11:21:44.837 回答