简体   繁体   English

如何使用JavaScript设置Telerik RadEditor的StripFormattingOnPaste属性?

[英]How do I set the StripFormattingOnPaste property of a Telerik RadEditor with JavaScript?

I don't have access to the actual asp.net server tag itself, so I need to change the StripFormattingOnPaste property to the EditorStripFormattingOptions enum with JavaScript and I'm not sure how. 我无权访问实际的asp.net服务器标签本身,因此我需要使用JavaScript将StripFormattingOnPaste属性更改为EditorStripFormattingOptions枚举 ,并且不确定如何。 I have some code that adds an OnClientLoad() and OnClientCommandExecuted() functions that works so I can add it in there, I'm just not sure where the property exists on the client-side and what the enum value would be: 我有一些代码添加了可以正常工作的OnClientLoad()OnClientCommandExecuted()函数,因此可以在其中添加它们,但我不确定该属性在客户端的位置以及枚举值是什么:

// init OnClientLoad and OnClientCommandExecuted event handlers for all radeditors on the page
Sys.Application.add_load(function() {
    if (typeof ($telerik) != "undefined") {
        if ($telerik.radControls && Telerik.Web.UI.RadEditor) {
            for (var i = 0, l = $telerik.radControls.length; i < l; i++) {
                var control = $telerik.radControls[i];
                if (Telerik.Web.UI.RadEditor.isInstanceOfType(control)) {
                    var editor = control;

                    // ??? editor._stripFormattingOptions = Telerik.Web.UI.StripFormattingOptions.NoneSupressCleanMessage

                    // editor already loaded, fire event
                    OnClientLoad(editor);
                    // attach event handler for paste commands
                    editor.add_commandExecuted(function(ed, args) {
                        return OnClientCommandExecuted(ed, args);
                    });
                }
            }
        }
    }
});

Update: I've discovered that the correct enum setting that I want is Telerik.Web.UI.StripFormattingOptions.NoneSupressCleanMessage . 更新:我发现我想要的正确的枚举设置是Telerik.Web.UI.StripFormattingOptions.NoneSupressCleanMessage

Update #2: I see that the RadEditor JS object has a _stripFormattingOptions property, but I think it might just be for private use. 更新#2:我看到RadEditor JS对象具有_stripFormattingOptions属性,但我认为它可能仅供私人使用。

The Telerik controls are based on ASP.NET AJAX and use pretty much the same coding conventions - public properties have getters and setters methods. Telerik控件基于ASP.NET AJAX并使用几乎相同的编码约定-公共属性具有getter和setter方法。 In this case you should use 在这种情况下,您应该使用

editor.set_stripFormattingOptions(Telerik.Web.UI.StripFormattingOptions.NoneSupressCleanMessage);

To get the current value, use 要获取当前值,请使用

var value = editor.get_stripFormattingOptions();

The property you saw (editor._stripFormattingOptions) is just used to store the value. 您看到的属性(editor._stripFormattingOptions)仅用于存储值。 Since its name starts with an underscore you are correct to assume that it is private and so you should not rely on it. 由于其名称以下划线开头,因此您可以正确地假设它是私有的,因此您不应依赖它。 The getter and setter methods are public and you are free to use them. getter和setter方法是公共的,您可以自由使用它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM