CodeMirror缺少行号,它只显示一个简单的textarea

时间:2016-08-23 06:26:12

标签: numbers line mirror

我已将 CodeMirror 与下面的代码

集成在一起
<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>

它仅显示正常的textarea,它看起来不像编辑器,并且缺少行号。如果我遗失了什么,请帮助我。

当我用var myTextarea = $("#myCode");替换行var myTextarea = $("#myCode")[0]时,它也会显示编辑器。

1 个答案:

答案 0 :(得分:0)

看看这个fiddle

HTML:

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

JS:

<?php

$con=mysqli_connect('localhost ','root','');
mysqli_select_db("tracer1",$con);

$latlong=$_POST['latlong'];


mysqli_query("insert into tracecoordinate2(latlong)values('{$latlong}')");

?>