<!DOCTYPE html>
<html>
<head>
<title>Demo of ACE Editor</title>
<!--導入js庫-->
<script src="ace-builds-master/src/ace.js"></script>
<script src="ace-builds-master/src/ext-language_tools.js"></script>
</head>html
<body>
<!--代碼輸入框(注意請務必設置高度,不然沒法顯示)-->
<pre id="code" class="ace_editor" style="min-height:400px">
<textarea class="ace_text-input">
#include <cstdio>
int main(){
int n,m;
scanf("%d %d",&n,&m);
printf("%d",n+m);
return 0;
}
</textarea>
</pre>git
<script>
//初始化對象
editor = ace.edit("code");github
//設置風格和語言(更多風格和語言,請到github上相應目錄查看)
theme = "clouds"
language = "c_cpp"
editor.setTheme("ace/theme/" + theme);
editor.session.setMode("ace/mode/" + language);session
//字體大小
editor.setFontSize(18);字體
//設置只讀(true時只讀,用於展現代碼)
editor.setReadOnly(false);ui
//自動換行,設置爲off關閉
editor.setOption("wrap", "free")code
//啓用提示菜單
ace.require("ace/ext/language_tools");
editor.setOptions({
enableBasicAutocompletion: true,
enableSnippets: true,
enableLiveAutocompletion: true
});
</script>htm
</body>
</html>對象