获取CodeMirror实例 [英] Get CodeMirror instance

查看:442
本文介绍了获取CodeMirror实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获得CodeMirror的一个实例(它绑定到textarea'#code')。从onclick-event我想要为CodeMirror实例的当前值添加一个值。怎么能实现这一目标?从文档中我似乎找不到任何东西来获取实例并将其绑定到javascript中的loca var。

I want to get an instance of CodeMirror (it is binded to a textarea '#code'). From an onclick-event I want to add a value to the current value of the CodeMirror instance. How can this be achieved? From the docs I can't seem to find anything to get an instance and bind it to a loca var in javascript.

推荐答案

有人刚发布了一个答案,但删除了它。然而,这是一个有效的解决方案。
谢谢!

Someone just posted an answer but removed it. Nevertheless, it was a working solution. Thanks!

- 基本上这是他的解决方案:

-- Basically this was his solution:

// create an instance
var editor = CodeMirror.fromTextArea('code');
// store it
$('#code').data('CodeMirrorInstance', editor);
// get it
var myInstance = $('code').data('CodeMirrorInstance');
// from here on the API functions are available to 'myInstance' again.

这篇关于获取CodeMirror实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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