문제

I created a textarea to highlight text for C# code using CodeMirror. But when I try to get the value of textarea I'm failing.

I'm creating my editor as

var editor = CodeMirror.fromTextArea(document.getElementById("txtCode"), {
    lineNumbers: true,
    mode: "text/x-csharp",
    matchBrackets: true
});

When I write some meaningless words and try to get value like this:

alert(document.getElementById("txtCode").value); 

It returns:

if(true){}else{}

When I try to get it like:

alert(document.getElementById("txtCode").getValue());

The browser gives the error "Uncaught TypeError: Object # has no method 'getValue'"

How can I get this value?

도움이 되었습니까?

해결책

Use editor.getValue();

alert(editor.getValue());
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top