这是一个 TinyMCE Fiddle,它展示了如何做你想做的事:
http://fiddle.tinymce.com/orgaab/1
关键代码是这样的:
setup: function (editor) {
editor.addButton('custombutton', {
type: 'listbox',
text: 'Custom Listbox',
icon: false,
onselect: function (e) {
editor.insertContent(this.value());
},
values: [
{ text: 'Bold Text', value: ' <strong>Some bold text!</strong>' },
{ text: 'Italic Text', value: ' <em>Some italic text!</em>' },
{ text: 'Regular Text', value: ' Some plain text ...' }
]
});
}
如果您想向菜单添加内容(根据您的后续评论),您可以这样做:
http://fiddle.tinymce.com/orgaab/4
本次更新的关键代码是:
editor.addMenuItem('custommenuoptions', {
separator: 'before',
text: 'Custom Menu Options',
context: 'insert',
prependToContext: true,
menu: [
{ text: 'Bold Text', onclick: function() {editor.insertContent(' <strong>Some bold text!</strong>')} },
{ text: 'Italic Text', onclick: function() {editor.insertContent(' <em>Some italic text!</em>')} },
{ text: 'Regular Text', disabled: true, onclick: function() {editor.insertContent(' Some plain text ...')} }
]
});