使用 JavaScript 打开和关闭 CKEditor 4 内联编辑

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12845850/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 17:15:00  来源:igfitidea点击:

Turning CKEditor 4 inline editing on and off with JavaScript

javascriptjqueryckeditor

提问by izip

I need to be able to toggle inline editing on/off with a button. See here for example of inline editing: http://nightly-v4.ckeditor.com/3559/samples/inlineall.html

我需要能够使用按钮打开/关闭内联编辑。有关内联编辑的示例,请参见此处:http: //nightly-v4.ckeditor.com/3559/samples/inlineall.html

My markup is as so:

我的标记是这样的:

<div contenteditable='true'>Mycontent</div>

Using jQuery I want to be able to turn on/off the editor.

使用 jQuery 我希望能够打开/关闭编辑器。

I have tried setting contenteditableto false, but this does not work. The editor is not loading back into the page on toggling the contenteditablesetting.

我试过设置contenteditable为false,但这不起作用。切换contenteditable设置时,编辑器不会重新加载到页面中。

Addendum: I also needed to destroy all CKEditor inline instances on a button click. Here is how I did that:

附录:我还需要在单击按钮时销毁所有 CKEditor 内联实例。这是我如何做到的:

        //kill all ckeditors
        for(k in CKEDITOR.instances){
            var instance = CKEDITOR.instances[k];
            instance.destroy();
        }

采纳答案by Reinmar

jQuery won't help you. Use CKEditor's API. E.g. you can destroy editor each time you want to turn it off (see http://nightly-v4.ckeditor.com/ckeditor_api/#!/api/CKEDITOR.editor-method-destroy) and initialize again to turn it on. There may be other ways to "turn editor off", but you'd have to be more precise what does it mean for you.

jQuery 不会帮助你。使用 CKEditor 的 API。例如,您可以在每次想要关闭编辑器时销毁它(请参阅http://nightly-v4.ckeditor.com/ckeditor_api/#!/api/CKEDITOR.editor-method-destroy)并再次初始化以将其打开。可能还有其他方法可以“关闭编辑器”,但您必须更准确地说明这对您意味着什么。