我試圖添加一個按鈕來更改Redactor JS中的字體大小,但它不起作用。這裏是我的代碼intialise主編:添加字體大小爲Redactor JS
$('#redactor_content').redactor({
buttons: buttons,
buttonsCustom: {
superscript: {
title: 'Superscript',
callback: function(obj, event, key) {
obj.execCommand('superscript')
}
},
subscript: {
title: 'Subscript',
callback: function(obj, event, key) {
obj.execCommand('subscript')
}
}
},
plugins: ['fontsize']
});
,這是我的插件:
RedactorPlugins.fontsize = {
init: function()
{
var fonts = [10, 11, 12, 14, 16, 18, 20, 24, 28, 30];
var that = this;
var dropdown = {};
$.each(fonts, function(i, s)
{
dropdown['s' + i] = { title: s + 'px', callback: function() { that.setFontsize(s); } };
});
dropdown['remove'] = { title: 'Remove font size', callback: function() { that.resetFontsize(); } };
this.buttonAdd('fontsize', 'Change font size', false, dropdown);
},
setFontsize: function(size)
{
this.inlineSetStyle('font-size', size + 'px');
},
resetFontsize: function()
{
this.inlineRemoveStyle('font-size');
}
};
但沒有出現在工具欄中。任何想法?我做錯了什麼嗎?
你的'buttons'變量是什麼?假設它是按鈕字符串數組,是否給它添加了「Superscript」和「Subscript」? – MForMarlon