【问题标题】:ace editor onchange not working王牌编辑器onchange不起作用
【发布时间】:2014-04-11 11:29:51
【问题描述】:

我正在使用 ace 编辑器在代码游乐场上工作,我正在尝试使用 ace 编辑器 onChange,但是当我键入时没有任何反应。
我的代码是

    <style>
    html{padding:0px}
    #editor { 
    border-radius:5px;
    width:500px;
    height:100%
}</style>
<a href="#" onclick="update()">go</a>
    <div id="editor" onChange="update()">
        function foo(items) {
            var x = "All this is syntax highlighted";
            return x;
        }
    </div>
    <script src="http://d1n0x3qji82z53.cloudfront.net/src-min-noconflict/ace.js" type="text/javascript" charset="utf-8"></script>
    <script>
        var editor = ace.edit("editor");
        editor.getSession().setUseWorker(false);
        editor.setTheme("ace/theme/monokai");
        editor.getSession().setMode("ace/mode/html");
        editor.getSession().on('change', function() {
update()
});


    </script>
    <script>;
        new function update()
        {
        var ace = editor.getSession().getValue();
        var divecho = document.getElementById("output");
        divecho.innerHTML=ace
        }</script>
        <div id="output"></div>

任何帮助将不胜感激

【问题讨论】:

  • 不应该只是editor.on('change', function() { update() });
  • 我离开了ace.c9.io/#nav=api&api=editor,其中有Editor.on("change"...);
  • @Teemu 我讨厌 JQuery,不是吗?每个人都使用它,并且在回答时不会提及它。编辑:k 我也尽量不使用它
  • 我怀疑原生 onchange 仅注册表单元素中的更改,例如 selectinput。艾斯修改的真正元素是什么?你的 div 只是一个包装器。尽管 API 本身包含一个自定义事件,正如 epascarello 在上面的评论中提到的那样。不,我不讨厌 jQuery,虽然我也不需要它......
  • @Teemu ACE 实际上是基于修改后的 JQuery

标签: javascript onchange ace-editor


【解决方案1】:
new function update()

应该是

function update()

此外,当 ace 是全局变量时,将其用作局部变量也是不明智的。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-03-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多