如何使用Javascript设置CodeMirror编辑器的值? [英] How can I set the value of a CodeMirror editor using Javascript?
本文介绍了如何使用Javascript设置CodeMirror编辑器的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试在以下代码中设置 id4
:
I try to set id4
in the following code:
<div id="id1">
<div id="id2">
<div id="id3">
<textarea id="id4"></textarea>
</div>
</div>
</div>
使用此代码:
document.getElementById('id4').value = "...";
这个:
document.getElementById('id3').getElementsByTagName('textarea')[0].value = "...";
但无效。
textarea
由CodeMirror编辑器取代。如何为其设置价值?
The textarea
is replaced by CodeMirror editor. How do I set value to it?
非常感谢您的帮助!
推荐答案
自3.0发布以来,这样做的方式略有改变。它现在是这样的:
The way to do this has changed slightly since the release of 3.0. It's now something like this:
var textArea = document.getElementById('myScript');
var editor = CodeMirror.fromTextArea(textArea);
editor.getDoc().setValue('var msg = "Hi";');
这篇关于如何使用Javascript设置CodeMirror编辑器的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文