codemirror可以在多个textareas上使用吗? [英] Can codemirror be used on multiple textareas?

查看:241
本文介绍了codemirror可以在多个textareas上使用吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可以在多个textarea上使用 codemirror 吗?我使用了许多动态生成的textareas。

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

<script type="text/javascript"> 
var editor = CodeMirror.fromTextArea('code', {
height: "dynamic",
parserfile: "parsecss.js",
stylesheet: "codemirror/css/csscolors.css",
path: "codemirror/js/"
});
</script>

我更喜欢在textarea上设置一个类来将它连接到codemirror。可能吗?解决它的另一种方法是设置多个ID。上面的代码设置IDcode以连接到codemirror。

I would prefer setting a class on the textarea to connect it to codemirror. Is it possible? The Another way of solving it would be to set multiple IDs. The code above sets the ID "code" to connect to codemirror.

推荐答案

您实际上可以多次调用 CodeMirror.fromTextArea 到'Codemirror-ify'多个textareas。

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

如果你想要多个textareas具有相同的选项,请包装 Codemirror.fromTextArea 调用函数,如:

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
    });
}

然后您可以将它应用于您的textareas,如:

You can then apply it to your textareas like:

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

这篇关于codemirror可以在多个textareas上使用吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆