ACE Editor OncHange no funciona
-
21-12-2019 - |
Pregunta
Estoy trabajando en un área de juegos de código usando ACE Editor y estoy tratando de usar ECE Editor OnChange, pero no pasa nada cuando escribo.
Mi código es
<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>
Cualquier ayuda será muy apreciada
Solución
new function update()
debe ser
function update()
Además, no es prudente usar as como una variable local cuando es global.
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow