Can codemirror be used on multiple textareas?

前端 未结 4 1346
情话喂你
情话喂你 2020-12-13 07:43

Can codemirror be used on more than one textarea? I use many textareas that are generated dynamically.



        
4条回答
  •  执笔经年
    2020-12-13 08:42

    You can actually make multiple calls to CodeMirror.fromTextArea to 'Codemirror-ify' multiple textareas.

    If you want multiple textareas with the same options, wrap the Codemirror.fromTextArea call in a function, like:

    function editor(id)
    {
        CodeMirror.fromTextArea(id, {
            height: "350px",
            parserfile: "parsexml.js",
            stylesheet: "css/xmlcolors.css",
            path: "js/",
            continuousScanning: 500,
            lineNumbers: true
        });
    }
    

    You can then apply it to your textareas like:

    editor('code1');
    editor('code2');
    

提交回复
热议问题