增加/减少RadEditor控件的FontSize按钮

时间:2014-04-10 14:03:21

标签: telerik radeditor

如何为RadEditor控件实现增加/减少 FontSize按钮,然后应在RadEditor工具栏中包含的<telerik:EditorTool Name="RealFontSize" />按钮中刷新新的字体大小

if Click in increase button, the realfontsize dropdown should increase in 1px as well as the font size of the selected text

例如,如图中的Click in increase按钮,realfontsize下拉列表应增加1px到17px以及所选文本的字体大小

更新 感谢@rdmptn回答:https://stackoverflow.com/a/23365866/432424我得到了第一个方法函数,但我仍然无法获得所选文本的当前fontSize:

Telerik.Web.UI.Editor.CommandList["IncreaseFontSize"] = function (commandName, editor, args) 
{
    if (editor.getSelectionHtml() != "")
    {
        var selection = editor.getSelection();
        var theSelectedElement = selection.getParentElement();
        var currentFontSize = parseInt(theSelectedElement.style.fontSize);
        currentFontSize++;
        editor.fire("FontSize", { value: currentFontSize.toString() }); }); //fire the FontSize command
    }
    else
    {
        alert("Please, select some text!");
        args.set_cancel(true);
    }
};

更新2: 这个功能很好用:

Telerik.Web.UI.Editor.CommandList["IncreaseFontSize"] = function (commandName, editor, args) 
{
    if (editor.getSelectionHtml() != "") 
    {
        var selection = editor.getSelection();
        var theSelectedElement = selection.getParentElement().firstElementChild;
        var currentFontSize = parseInt(theSelectedElement.size);
        currentFontSize++;
        var strNewFontSize = currentFontSize.toString();
        editor.fire("FontSize", { value: strNewFontSize }); //fire the FontSize command    
    }
    else
    {
        alert("Please, select some text!");
        args.set_cancel(true);
    }
};

1 个答案:

答案 0 :(得分:1)

以下是一些资源:

http://demos.telerik.com/aspnet-ajax/editor/examples/customtools/defaultcs.aspx

http://www.telerik.com/help/aspnet-ajax/editor-adding-your-own-buttons.html

演示中的第一个工具显示了如何触发fontSize更改命令。使用选择和逻辑来确定当前大小和所需大小:http://www.telerik.com/help/aspnet-ajax/editor-getselection.html