使用Javascript / jQuery更改Telerik RadEditor的值
我正在尝试使用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("" + html + "")); } }); editorSaveEventInit = true; } } }; $(window).load(function () { InitSaveEvent(); });
有没有办法用JavaScript访问Telerik RadEditor对象(使用OnClientCommandExecuted()
?),以便我可以访问.get_html()
和.set_html(value)
函数? 如果没有,在发回之前我需要设置什么值?
为什么不使用自定义内容filter 。
啊,刚刚发现了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; } } };