ace editor onchange not working

不想你离开。 提交于 2019-12-08 12:30:57

问题


i'm working on a code playground using ace editor and i am trying to use ace editor onChange but nothing happens when I type.
my code is

    <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>

Any help will be greatly appreciated


回答1:


new function update()

should be

function update()

Also it is not wise to use ace as a local variable when it is a global.



来源:https://stackoverflow.com/questions/23011386/ace-editor-onchange-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!