1

I am developing a project using codemirror in an aspx page. Here is my code:

<form><textarea id="code" name="code" >

<script type="text/javascript">

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

        var txt = "myText";
        $('textarea#code').text(txt);
    }
</script>

So i want every time that i am pushing the button i want to put the value of the variable txt into the codemirror's text area. Instead when i am clicking it nothing happens to the text area. Any help pls ?

4

1 に答える 1

6

If you want to set the value of a CodeMirror there's the .setValue method:

function app() {
    var txt = "myText";
    editor.setValue(txt);
}
于 2012-07-18T16:28:29.593 に答える