CodeMirror缺少行号,它仅显示一个简单的文本区域 [英] CodeMirror missing line numbers, it shows a simple textarea only

查看:156
本文介绍了CodeMirror缺少行号,它仅显示一个简单的文本区域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已将 CodeMirror 与以下代码集成在一起,

I have integrated CodeMirror with below code,

<style>
.CodeMirror {
    border-top: 1px solid #888; 
    border-bottom: 1px solid #888;
}
</style>
<body>
    <textarea id="myCode"></textarea>    
    <script type="text/javascript">
      window.onload = function() {
        var myTextarea = $("#myCode")[0];
        editor = CodeMirror.fromTextArea(myTextarea, {
          lineNumbers: true
        });
      };
    </script>
</body>

它仅显示普通的文本区域,看起来不像编辑器,并且行号丢失.如果我缺少任何东西,请帮助我.

It shows a normal textarea only, which doesn't look like an editor and the line numbers are missing. Please help me if anything I am missing.

当我将 var myTextarea = $(#myCode"); 行替换为 var myTextarea = $(#myCode")[0] 时,将显示编辑器也是如此.

When I replace the line var myTextarea = $("#myCode"); with var myTextarea = $("#myCode")[0], it displays the edotor as well.

推荐答案

查看此小提琴

HTML:

<textarea id="code"></textarea>

JS:

var minLines = 5;
var startingValue = '';
for (var i = 1; i < minLines; i++) {
    startingValue += '\n';
}

var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
    lineNumbers: true,
    gutter: true,
    lineWrapping: true,
    value: startingValue
});

//FIX FOR MIN LINES
//http://stackoverflow.com/questions/10380759/codemirror-minimum-lines-number
editor.setValue(startingValue);

这篇关于CodeMirror缺少行号,它仅显示一个简单的文本区域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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