简体   繁体   English

将文本从变量放入Codemirror Textarea

[英]Put text from variable into codemirror textarea

I am developing a project using codemirror in an aspx page. 我正在aspx页面中使用codemirror开发项目。 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. 因此,我想每次按下按钮时都想将变量txt的值放入codemirror的文本区域。 Instead when i am clicking it nothing happens to the text area. 相反,当我单击它时,文本区域没有任何反应。 Any help pls ? 有什么帮助吗?

If you want to set the value of a CodeMirror there's the .setValue method: 如果要设置CodeMirror的值,则可以使用.setValue方法:

function app() {
    var txt = "myText";
    editor.setValue(txt);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM