【问题标题】:How to embed a code editor in a website如何在网站中嵌入代码编辑器
【发布时间】:2018-06-07 07:18:40
【问题描述】:
<!DOCTYPE html>
<html lang="en">
<head>
<title>ACE in Action</title>
<style type="text/css" media="screen">
    #editor { 
        position: absolute;
        top: 0;
        right: 0;
        bottom: 0;
        left: 0;
    }
</style>
</head>
<body>

<div id="editor">function foo(items) {
    var x = "All this is syntax highlighted";
    return x;
}</div>

<script src="/ace-builds/src-noconflict/ace.js" type="text/javascript" charset="utf-8"></script>
<script>
    var editor = ace.edit("editor");
    editor.setTheme("ace/theme/monokai");
    editor.session.setMode("ace/mode/javascript");
</script>
</body>
</html>

我已经尝试过 ace 代码编辑器,我已经在我的网页上粘贴了确切的代码,但它不工作,请你帮帮我,我希望我的编辑器与 w3school 代码编辑器一样。

【问题讨论】:

    标签: html embed webpage code-editor


    【解决方案1】:

    您在脚本 src 属性中提到的路径中似乎没有 ace.js。

    替换

    <script src="/ace-builds/src-noconflict/ace.js" type="text/javascript" charset="utf-8"></script>
    

    与

    <script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.3.3/ace.js" type="text/javascript" charset="utf-8"></script>
    

    【讨论】:

      【解决方案2】:

      在脚本中使用 cdn,或者您可以在本地获取库并尝试该脚本

      &lt;script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.3.3/ace.js" type="text/javascript" charset="utf-8"&gt;&lt;/script&gt;

      【讨论】:

      • 我们可以使用 Ace 代码编辑器编译代码吗?我相信它不会,但有点困惑,有人可以帮忙解答
      猜你喜欢
      • 2015-11-27
      • 2011-10-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多