我正在使用TinyMCE 4.x(最新版本),我想在'init'事件中为工具栏按钮设置默认值。例如:
tinymce.init({
selector: 'selector-id',
// more options...
setup: function (ed) {
ed.on('init', function () {
// changes the 'font-size' input select
var fontSizeButton = ed.getToolbarButtonByName('font-size');
fontSizeButton.setValue('18pt');
// changes the 'bold' button state
var boldButton = ed.getToolbarButtonByName('bold');
boldButton.setValue(true);
}
}
});
当然,“getToolbarButtonByName”函数不存在。我发明了它来说明这个想法。是否可以按名称获取工具栏按钮,然后更改其值?
答案 0 :(得分:0)
回答自己。您可以使用execCommand函数: http://www.tinymce.com/wiki.php/API3:method.tinymce.execCommand
此功能执行一些操作并刷新工具栏按钮。我以前的代码看起来像这样:
tinymce.init({
selector: 'selector-id',
// more options...
setup: function (ed) {
ed.on('init', function () {
// changes some font styles and refreshes the toolbar buttons
ed.execCommand('FontName', false, 'courier new,courier');
ed.execCommand('FontSize', false, '24pt');
ed.execCommand('Bold');
}
}
});