如何从 ACE 编辑器中获取价值? [英] How do I get value from ACE editor?

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

问题描述

我第一次使用 ACE 编辑器.我有以下相关问题.

<块引用>

  1. 如何在页面上找到ACE 编辑器的实例?我不要维护一个将保存编辑器实例的全局变量.一世需要按需查找其实例.

  2. 如何获取和设置它的值?

我愿意为任何比 ACE 编辑器更好的编辑器提供建议,该编辑器将支持几乎所有类型的语言/标记/css 等,并与 jQuery 高度集成.>

解决方案

根据他们的 API:

标记:

<div id="aceEditor" style="height: 500px; width: 500px">一些文字</div>

查找实例:

var editor = ace.edit("aceEditor");

获取/设置值:

var code = editor.getValue();editor.setValue("这里有新代码");

根据我的经验,Ace 是我见过的最好的代码编辑器.还有一些其他的,例如 CodeMirror 等,但我发现它们不如 Ace 有用或难以集成.>

这是一个比较此类编辑器的 Wiki 页面.

还有一个付费的,我没试过(我现在不记得了).以后能找到的话会更新的.

I am using ACE editor for the first time. I have the below questions related to it.

  1. How do I find the instance of ACE editor on the page? I don't want to maintain a global variable which will hold the editor instance. I need to find its instance on demand.

  2. How to get and set its value?

I am open for suggestions for any better editor than ACE editor which will support almost all types of language/markup/css etc and highly integrated with jQuery.

解决方案

Per their API:

Markup:

<div id="aceEditor" style="height: 500px; width: 500px">some text</div>

Finding an instance:

var editor = ace.edit("aceEditor");

Getting/Setting Values:

var code = editor.getValue();

editor.setValue("new code here");

Based on my experience, Ace is the best code editor I've seen. There are few others such as CodeMirror etc. but I found them to be less useful or difficult to integrate than Ace.

Here's a Wiki page for comparision of such editors.

There is a paid one also which I haven't tried (and I can't remember for now). Will updated later if I can find it.

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

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