2

我使用 CodeMirror 创建了一个 textarea 来突出显示 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());

浏览器给出错误“Uncaught TypeError: Object # has no method 'getValue'”

我怎样才能得到这个值?

4

1 回答 1

6

使用editor.getValue();

alert(editor.getValue());
于 2013-10-22T16:35:12.990 回答