0

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

如果单击增加按钮,realfontsize 下拉菜单应该增加 1px 以及所选文本的字体大小

例如从图中如果单击增加按钮,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);
    }
};
4

1 回答 1

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 。

于 2014-04-29T13:19:57.660 回答