如codemirror.net中所示
创建一个<textarea>
元素,它将替换您当前的<pre>
标签。readonly
如果您不喜欢编辑,请将 textarea 设置为。
<textarea id="myTextarea" readonly>
... your code for highlighting goes here ...
</textarea>
<link rel="stylesheet" href="lib/codemirror.css">
<script src="lib/codemirror.js"></script>
<script>
var editor = CodeMirror.fromTextArea(document.getElementById("myTextarea"), {
lineNumbers: true
});
</script>
由公共类名选择的多个实例:
var areas = document.getElementsByClassName("myTextareaClass");
for(var i = 0; i < areas.length; i++) {
CodeMirror.fromTextArea(areas.item(i), {lineNumbers: true});
}