TinyMCE添加多个自定义工具栏按钮

3
我正在按照http://tinymce.moxiecode.com/tryit/custom_toolbar_button.php上的教程进行操作,但需要添加多个自定义按钮。
以下是添加一个按钮的代码块,但我需要添加多个按钮,不知道该怎么做。
setup : function(fn) {
    // Add a custom button
    fn.addButton('firstname', {
        title : 'Member First Name',
        image : 'resources/scripts/tiny_mce/themes/advanced/img/firstname.gif',
        onclick : function() {
            // Add you own code to execute something on click
            fn.focus();
            fn.selection.setContent('{firstname}');
        }
    });
}

感谢您的帮助。
1个回答

9

只需多次调用fn.addButton即可:

setup : function(fn) {
    // Add a custom button
    fn.addButton('firstname', {
        title : 'Member First Name',
        image : 'resources/scripts/tiny_mce/themes/advanced/img/firstname.gif',
        onclick : function() {
            // Add you own code to execute something on click
            fn.focus();
            fn.selection.setContent('{firstname}');
        }
    });
    fn.addButton('lastname', {
        title : 'Member Last Name',
        image : 'resources/scripts/tiny_mce/themes/advanced/img/lastname.gif',
        onclick : function() {
            // Add you own code to execute something on click
            fn.focus();
            fn.selection.setContent('{lastname}');
        }
    });
}

如果你要定义工具栏布局,例如:toolbar
toolbar: "insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image | firstname",

记得添加新的id(例如lastname


非常感谢您,Molle博士, 我本来想的更难一些。您的回答对我帮助很大! - drhoo

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接