【问题标题】:How to dynamically switch modes with CodeMirror?如何使用 CodeMirror 动态切换模式?
【发布时间】:2011-05-25 20:34:21
【问题描述】:

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

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

【问题讨论】:

    标签: codemirror


    【解决方案1】:

    这样的事情会对你有所帮助。

    首先,设置CodeMirror:

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

    然后,改变模式

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

    【讨论】:

      【解决方案2】:

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

      对于 CodeMirror 1,使用 setParser method

      【讨论】:

      • CodeMirror 3 怎么样?
      猜你喜欢
      • 2020-08-03
      • 1970-01-01
      • 1970-01-01
      • 2020-04-12
      • 2016-01-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多