codemirror 简单使用

代码压缩包地址 https://github.com/codemirror/codemirror

1. 网页引用<script src="js/codemirror.js"></script>

2. 网页引用<script src="js/clike.js"></script>(mode属性需要的js文件)

3. 初始化编辑框生成

var myTextarea = document.getElementById("smartTxt");

var editor = CodeMirror.fromTextArea(myTextarea,{
    lineNumbers: true,           
    matchBrackets: true,
    mode:"text/x-solidity",  (此属性代表着代码风格,比如js,c/c++,java等,需要引用clike.js)
    showCursorWhenSelecting: true,     
    inputStyle: "contenteditable",
    styleActiveLine: { nonEmpty: true }

  })


4.在做项目中还有用到一些属性

      editor.focus();                      聚焦到编辑框

      editor.setCursor(lineNumber); 为某行设置光标

      editor.addLineClass(lineNumber, 'text', 'analysis-matched-line'); 为某一行添加class样式

      editor.removeLineClass(lineNumber, 'text', 'analysis-matched-line'); 为某一行删除class样式


猜你喜欢

转载自blog.csdn.net/u013466380/article/details/79790935