【问题标题】:Changing the value of a Telerik RadEditor with Javascript/jQuery使用 Javascript/jQuery 更改 Telerik RadEditor 的值
【发布时间】:2010-11-17 01:39:11
【问题描述】:

我正在尝试使用 Javascript 手动清理 Telerik RadEditor 的 HTML,但我似乎无法找到存储该值的正确位置,以便在回发时将其保存。

这是我的 JS:

$(function () {    
    jQuery.fixHash = function ($html) {      

        // modify $html

        return $html;
    };

    $("#adminEditingArea input[id$='SaveButton']").unbind("click").click(function () {
        $("iframe[id$='_contentIframe']").trigger("save");

        // call .net postback

        return false;
    });

});

var editorSaveEventInit = false;
function InitSaveEvent() {
    if (!editorSaveEventInit) {
        var $EditFrames = $("iframe[id$='_contentIframe']");
        if ($EditFrames && $EditFrames.length > 0) {
            $EditFrames.bind("save", function (e) {
                var $thisFrame = $(this);
                var thisFrameContents = $thisFrame.contents();
                if (thisFrameContents) {
                    var telerikContentIFrame = thisFrameContents.get(0);
                    var $body = $("body", telerikContentIFrame);
                    var html = $.fixHash($body).html();
                    $body.html(html);

                    // also tried storing the modified HTML in the textarea, but it doesn't seem to save:
                    //$thisFrame.prev("textarea").html(encodeURIComponent("<body>" + html + "</body>"));
                }
            });
            editorSaveEventInit = true;
        }
    }
};

$(window).load(function () {
    InitSaveEvent();
});

有什么方法可以使用 JavaScript 访问 Telerik RadEditor 对象(使用OnClientCommandExecuted()?),以便我可以访问.get_html().set_html(value) 函数?如果没有,在回发之前我需要设置什么值?

【问题讨论】:

    标签: asp.net javascript jquery telerik radeditor


    【解决方案1】:

    你为什么不使用custom content filters

    【讨论】:

    • 太棒了,我什至不知道这些是可能的。我认为重构我当前的解决方案可能有点晚,但将来肯定会派上用场,谢谢!
    【解决方案2】:

    啊,刚刚发现Telerik内置的$find()函数:http://www.telerik.com/help/aspnet-ajax/editor_getingreferencetoradeditor.html

    编辑:这是我为InitSaveEvent() 函数提出的解决方案:

    var editorSaveEventInit = false;
    function InitSaveEvent() {
        if (!editorSaveEventInit) {
            var $EditFrames = $("iframe[id$='_contentIframe']");
            if ($EditFrames && $EditFrames.length > 0) {
                $EditFrames.bind("save", function (e) {
                    var $thisFrame = $(this);
                    var thisFrameContents = $thisFrame.contents();
                    if (thisFrameContents) {
                        var telerikContentIFrame = thisFrameContents.get(0);
                        var $body = $("body", telerikContentIFrame);
                        var html = $.fixHash($body).html();
                        // SOLUTION!
                        var $radeditor = $thisFrame.parents("div.RadEditor.Telerik:eq(0)");
                        var editor = $find($radeditor.attr("id"));
                        editor.set_html(html);
                        // ☺
                    }
                });
                editorSaveEventInit = true;
            }
        }
    };
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-05-06
      • 1970-01-01
      • 2011-05-23
      • 2018-08-05
      • 2011-12-05
      • 2014-03-01
      • 1970-01-01
      相关资源
      最近更新 更多