下載地址:https://codeload.github.com/ajaxorg/ace-builds/zip/master
解壓后只需要在項目中導入src-noconflict這個文件夾就可以了寞冯。
div的高度一定要設(shè)置猛们,否則出不來遇伞。
<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");
//設(shè)置編輯器樣式贮尉,對應(yīng)theme-*.js文件
editor.setTheme("ace/theme/twilight");
//設(shè)置代碼語言咱娶,對應(yīng)mode-*.js文件
editor.session.setMode("ace/mode/javascript");
//設(shè)置打印線是否顯示
editor.setShowPrintMargin(false);
//設(shè)置是否只讀
editor.setReadOnly(true);
//以下部分是設(shè)置輸入代碼提示的开皿,如果不需要可以不用引用ext-language_tools.js
ace.require("ace/ext/language_tools");
editor.setOptions({
enableBasicAutocompletion: true,
enableSnippets: true,
enableLiveAutocompletion: true
});
</script>
editor.getValue();//獲取內(nèi)容
editor.setValue(value);//設(shè)置內(nèi)容