How do I make a textarea an ACE editor?

前端 未结 5 1437
温柔的废话
温柔的废话 2020-12-02 04:48

I\'d like to be able to convert specific textareas on a page to be ACE editors.

Does anyone have any pointers please?

EDIT:

I have the the editor.htm

5条回答
  •  攒了一身酷
    2020-12-02 05:53

    To create an editor just do:

    HTML:

    
    
    

    JS:

    var editor1 = ace.edit('code1');
    var editor2 = ace.edit('code2');
    editor1.getSession().setValue("this text will be in the first editor");
    editor2.getSession().setValue("and this in the second");
    

    CSS:

    #code1, code2 { 
      position: absolute;
      width: 400px;
      height: 50px;
    }
    

    They must be explicitly positioned and sized. By show() and hide() I believe you are referring to the jQuery functions. I'm not sure exactly how they do it, but it cannot modify the space it takes up in the DOM. I hide and show using:

    $('#code1').css('visibility', 'visible');
    $('#code2').css('visibility', 'hidden');
    

    If you use the css property 'display' it will not work.

    Check out the wiki here for how to add themes, modes, etc... https://github.com/ajaxorg/ace/wiki/Embedding---API

    Note: they do not have to be textareas, they can be whatever element you want.

提交回复
热议问题