如何获取Codemirror textarea的值 [英] How to get the value of Codemirror textarea
本文介绍了如何获取Codemirror textarea的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用Codemirror的textarea插件,但我无法检索textarea的值。
I am using Codemirror's plugin for textarea but I am not able to retrieve the value of textarea.
代码:
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
lineNumbers: true,
matchBrackets: true,
mode: "text/x-csrc"
});
function showCode()
{
var text = editor.mirror.getCode();
alert(text);
}
显示错误:
editor.getCode() is not a function.
推荐答案
尝试使用 getValue()
而不是 getCode()
。
将可选参数传入getValue(separator )指定用于分隔行的字符串(默认为 \ n
)。
Pass in an optional argument into getValue(separator) to specify the string to be used to separate lines (the default is \n
).
这篇关于如何获取Codemirror textarea的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文