如何让textarea成为ACE编辑器? [英] How do I make a textarea an ACE editor?

查看:151
本文介绍了如何让textarea成为ACE编辑器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够将页面上的特定textareas转换为ACE编辑器。

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

有人有任何指针吗?

编辑:

我有一个使用textarea的editor.html文件,但是只要我添加第二个,第二个未转换为编辑。

I have the the editor.html file working with one textarea, but as soon as I add a second, the second isn't converted to an editor.

编辑2:

我决定废除几个想法,而是在新窗口中打开一个。我的新困境是当我隐藏()并显示()textarea时,显示器出错了。任何想法?

I decided to scrap the idea of having several, and instead open one up in a new window. My new predicament is that when I hide() and show() the textarea, the display goes awry. Any ideas?

推荐答案

据我了解Ace的想法,你不应该做一个 textarea 一个王牌编辑本身。您应该创建一个额外的div并使用 .getSession()函数更新textarea。

As far as I understood the idea of Ace, you shouldn't make a textarea an Ace editor itself. You should create an additional div and update textarea using .getSession() function instead.

html

<textarea name="description"/>
<div id="description"/>

js

var editor = ace.edit("description");
var textarea = $('textarea[name="description"]').hide();
editor.getSession().setValue(textarea.val());
editor.getSession().on('change', function(){
  textarea.val(editor.getSession().getValue());
});

或只是致电

textarea.val(editor.getSession().getValue());

仅当您使用给定的textarea提交表单时。我不确定这是否是使用Ace的正确方法,但它是在 GitHub 上使用的方式。

only when you submit the form with the given textarea. I'm not sure whether this is the right way to use Ace, but it's the way it is used on GitHub.

这篇关于如何让textarea成为ACE编辑器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆