美文网首页
网页嵌入Ace Editor代码编辑器

网页嵌入Ace Editor代码编辑器

作者: 大话家丶 | 来源:发表于2017-05-03 09:35 被阅读0次

下载地址:https://codeload.github.com/ajaxorg/ace-builds/zip/master
解压后只需要在项目中导入src-noconflict这个文件夹就可以了。
div的高度一定要设置,否则出不来。

<div style="height:300px;" id="editorDiv"></div>
<script src="src-noconflict/ace.js" type="text/javascript" charset="utf-8"></script>
<script src="src-noconflict/ext-language_tools.js" type="text/javascript"></script>
<script>
    var editor = ace.edit("editorDiv");
    //设置编辑器样式,对应theme-*.js文件
    editor.setTheme("ace/theme/twilight");
    //设置代码语言,对应mode-*.js文件
    editor.session.setMode("ace/mode/javascript");
    //设置打印线是否显示
    editor.setShowPrintMargin(false);
    //设置是否只读
    editor.setReadOnly(true);
   
    //以下部分是设置输入代码提示的,如果不需要可以不用引用ext-language_tools.js
    ace.require("ace/ext/language_tools");
    editor.setOptions({
        enableBasicAutocompletion: true,
        enableSnippets: true,
        enableLiveAutocompletion: true
    });
</script>
editor.getValue();//获取内容
editor.setValue(value);//设置内容
参考资料

ACE Editor在线代码编辑器简介及使用引导

相关文章

网友评论

      本文标题:网页嵌入Ace Editor代码编辑器

      本文链接:https://www.haomeiwen.com/subject/aqkktxtx.html