3

我有一个定义如下的剑道编辑器:

 @(Html.Kendo().Editor()
          .Name("editor")
          .Tag("div")
          .Tools(tools => tools
                .Clear()
                .Bold().Italic().Underline().Strikethrough()
                .JustifyLeft().JustifyCenter().JustifyRight().JustifyFull()
                .CreateLink().Unlink()
                .InsertImage()
                .TableEditing()
                .FontColor().BackColor()
          )
          .Value(@<text>
             <p> You are inside the editor. And in the editor there are some
                 anchor tags. 
             </p>

我想将此编辑器设为只读,并将编辑器内的锚标记设为可点击。

我编写了下面的 Javascript 代码来实现这种行为。甚至遵循谷歌搜索和stackoverflow中类似帖子中提供的答案。但是没有一个工作,编辑器不是只读的。我仍然可以编辑。

下面是我试过的代码:

<script>
    var editor = $('#editor').data("kendoEditor"),
        editorBody = $(editor.body);

    // make readonly
    editorBody.removeAttr("contenteditable").find("a").on("click.readonly", false);

</script>  

请建议我哪里出错了,我该如何实现这种行为。

TIA 为您提供帮助!

4

1 回答 1

4

以下代码段将使 Kendo HTML 编辑器成为只读:

var editor = $("#editor").data().kendoEditor;
var editorBody = $(editor.body)
editorBody.attr("contenteditable", false);

或者,如果您觉得需要简洁,可以将其全部包装成一行:

$($("#editor").data().kendoEditor.body).attr("contenteditable", false);

如果您需要在读/写和只读之间切换编辑器,我建议将此片段包装在它自己的小函数中,并将其直接绑定到您要用于切换的按钮/锚点/等上的单击事件行为。

在Kendo UI v2015.3.1111上测试了这个功能;旧版本 API 上的 YMMV。

于 2016-11-12T01:01:32.297 回答