如何使用CodeMirror动态切换模式?

时间:2011-05-25 20:34:22

标签: codemirror

如何使用CodeMirror动态切换模式?

我有默认设置,但需要切换它。

2 个答案:

答案 0 :(得分:15)

这样的事情可以帮助你。

首先设置代码镜像

this.editor = CodeMirror.fromTextArea(document.getElementById("testAreaCodeMirror"), {
    lineNumbers: true,
    matchBrackets: true,
    styleActiveLine: true,
    theme:"eclipse",
    mode:language
});

然后改变模式

this.editor.setOption("mode", language);

答案 1 :(得分:13)

如果这是CodeMirror 2或3,请使用setOption("mode", <new mode>)setOption的文档,"mode")。

对于CodeMirror 1,请使用setParser method

相关问题