使用 Javascript/jQuery 更改 Telerik RadEditor 的值

发布于 2024-08-01 20:59:53 字数 1669 浏览 11 评论 0原文

我正在尝试使用 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) 函数? 如果没有,在回发之前我需要设置什么值?

I'm trying to manually clean the HTML of a Telerik RadEditor with Javascript but I can't seem to find the correct place to store the value so that it gets saved on post back.

Here's the JS I have:

$(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();
});

Is there any way to access the Telerik RadEditor object with JavaScript (using OnClientCommandExecuted()?) so that I can access the .get_html() and .set_html(value) functions? If not, what values do I need to set before posting back?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

栖竹 2024-08-08 20:59:53

啊,刚刚发现了 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;
        }
    }
};

Ah, just discovered Telerik's built-in $find() function: http://www.telerik.com/help/aspnet-ajax/editor_getingreferencetoradeditor.html

Edit: here's the solution I came up with for my InitSaveEvent() function:

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;
        }
    }
};
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文