简体   繁体   English

CodeMirror删除编辑器实例

[英]CodeMirror delete a editor instance

I am using CodeMirror to do some syntax highlighting in my web. 我正在使用CodeMirror在我的网站上进行一些语法高亮显示。 I've created two radio buttons in my html. 我在我的html中创建了两个单选按钮。 And my JavaScript code is as follows: 我的JavaScript代码如下:

if(flag == "C")
    Editor = CodeMirror.fromTextArea(textArea, {
    lineNumbers: true,
    matchBrackets: true,
    mode: "text/x-csrc"
});
else if(flag == "Cpp")
    Editor.off(0);
    Editor = CodeMirror.fromTextArea(textArea, {
    lineNumbers: true,
    matchBrackets: true,
    mode: "text/x-c++src"
});

It does complete the function of syntax highlighting, but the problem is when I click the radio button multiple times, it just create as many as I click, and this is annoying. 它确实完成了语法高亮的功能,但问题是当我多次单击单选按钮时,它只创建了我点击的数量,这很烦人。 So I am wondering is there any way to delete the previous editor instance before I create a new one? 所以我想知道在创建新的编辑器实例之前有没有办法删除以前的编辑器实例?

cm.getWrapperElement() → Element Returns the DOM node that represents the editor, and controls its size. cm.getWrapperElement()→元素返回表示编辑器的DOM节点,并控制其大小。 Remove this from your tree to delete an editor instance. 从树中删除它以删除编辑器实例。

See the documentation. 请参阅文档。 http://codemirror.net/doc/manual.html http://codemirror.net/doc/manual.html

Editors created with fromTextArea have a toTextArea method to remove them. 使用fromTextArea创建的编辑器有一个toTextArea方法来删除它们。 Alternatively, simply create the editor once and use Editor.setOption("mode", "text/x-csrc") . 或者,只需创建一次编辑器并使用Editor.setOption("mode", "text/x-csrc")

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

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