【发布时间】:2014-10-14 17:09:51
【问题描述】:
我想像 microsoft word 中那样增加和减少字体大小。 我需要一个快捷方式来增加和一个减少。 目前我有这个:
tinymce.PluginManager.add('ds_fontsize', function (editor, url) {
editor.addMenuItem('fontsize_up', {
text: 'fontsize_up',
icon: false,
onclick: function () {
editor.execCommand('fontsize_up');
}
});
editor.addMenuItem('fontsize_down', {
text: 'fontsize-down',
icon: false,
onclick: function () {
editor.execCommand('fontsize_down');
}
});
editor.addCommand('fontsize_down', function () {
var content = tinymce.activeEditor.selection.getContent();
var node = tinymce.activeEditor.selection.getNode();
var fontsize = tinymce.activeEditor.dom.getStyle(node, 'font-size', true);
fontsize = fontsize.split("px", 1)
fontsize--;
//remove old span
tinyMCE.activeEditor.execCommand('mceReplaceContent', false, '', 'span');
tinyMCE.activeEditor.selection.setNode(tinyMCE.activeEditor.dom.create('span', { style: 'font-size: 15px' }, content));
});
editor.addCommand('fontsize_up', function () {
var content = tinymce.activeEditor.selection.getContent();
var node = tinymce.activeEditor.selection.getNode();
var fontsize = tinymce.activeEditor.dom.getStyle(node, 'font-size', true);
fontsize = fontsize.split("px", 1)
fontsize++;
//remove old span
tinyMCE.activeEditor.execCommand('mceReplaceContent', false, '', 'span');
tinyMCE.activeEditor.selection.setNode(tinyMCE.activeEditor.dom.create('span', { style: 'font-size:' + fontsize + 'px' }, content));
});
});
好的,这主要是有效的,但是如果我增加或减少超过一个大小,旧跨度就不会删除。 我得到这样的 HTML 代码:
<p><span style="font-size:12px"><span style="font-size:13px">Hello World</span></span></p>
有没有人可以为我提供解决方案或其他方式来做到这一点?
谢谢菲利克斯
【问题讨论】:
标签: javascript html tinymce font-size