<!DOCTYPE html>
<html>
<head>
<title>JS 代码编辑器</title>
<script src="https://cdn.jsdelivr.net/npm/ace-builds/src-noconflict/ace.js"></script>
<style>
#editor {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
}
</style>
</head>
<body>
<div id="editor"></div>
<script>
// 初始化 Ace 编辑器
var editor = ace.edit("editor");
editor.setTheme("ace/theme/monokai"); // 设置主题为 Monokai
editor.session.setMode("ace/mode/javascript"); // 设置语言模式为 JavaScript
// 设置编辑器的一些配置
editor.setOptions({
enableBasicAutocompletion: true, // 启用基本自动补全
enableSnippets: true, // 启用代码片段
enableLiveAutocompletion: true // 启用实时自动补全
});
</script>
</body>
</html>
引入 Ace 编辑器:
<script>
标签从 CDN 引入 Ace 编辑器的 JavaScript 文件。HTML 结构:
div
元素,其 id
为 editor
,用于容纳代码编辑器。CSS 样式:
#editor
设置为占满整个浏览器窗口。初始化 Ace 编辑器:
ace.edit("editor")
方法初始化编辑器,并将其绑定到 #editor
元素。Monokai
,这是一种常见的深色主题。JavaScript
。配置编辑器选项:
上一篇:js 在线编辑器
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站