Javascript CodeMirror如何获取Textarea值

Javascript CodeMirror如何获取Textarea值,javascript,textarea,codemirror,Javascript,Textarea,Codemirror,我使用CodeMirror创建了一个文本区域来突出显示C代码的文本。但是当我尝试获取textarea的值时,我失败了 我正在创建我的编辑器 var editor = CodeMirror.fromTextArea(document.getElementById("txtCode"), { lineNumbers: true, mode: "text/x-csharp", matchBrackets: true }); 当我写一些毫无意义的话,并试图得到这样的价值: al

我使用CodeMirror创建了一个文本区域来突出显示C代码的文本。但是当我尝试获取textarea的值时,我失败了

我正在创建我的编辑器

var editor = CodeMirror.fromTextArea(document.getElementById("txtCode"), {
    lineNumbers: true,
    mode: "text/x-csharp",
    matchBrackets: true
});
当我写一些毫无意义的话,并试图得到这样的价值:

alert(document.getElementById("txtCode").value); 
它返回:

if(true){}else{}
当我试着让它像:

alert(document.getElementById("txtCode").getValue());
浏览器给出错误“UncaughtTypeError:Object”没有方法“getValue”

如何获取该值?

使用

getValue()
是CM对象的方法,而不是HTML元素:
alert(editor.getValue())
alert(editor.getValue());