Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/84.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript JQuery如何更改CodeMirror中textarea的字符串值_Javascript_Jquery_Codemirror - Fatal编程技术网

Javascript JQuery如何更改CodeMirror中textarea的字符串值

Javascript JQuery如何更改CodeMirror中textarea的字符串值,javascript,jquery,codemirror,Javascript,Jquery,Codemirror,我正在尝试动态更改textarea的字符串值。在我的代码setValue函数中,应该这样做,但每当我尝试时,文本区域都会被更改,但之后就不可编辑了。 什么会导致问题 function createScriptPanel(value, container, mode) { var scriptPanel = $('<div id="editor"><textarea id="editor-code">' + value.script + '</t

我正在尝试动态更改textarea的字符串值。在我的代码setValue函数中,应该这样做,但每当我尝试时,文本区域都会被更改,但之后就不可编辑了。 什么会导致问题

   function createScriptPanel(value, container, mode) {
        var scriptPanel = $('<div id="editor"><textarea id="editor-code">' + value.script + '</textarea></div>').appendTo(container);
        CodeMirror.commands.autocomplete = function (cm) {
            CodeMirror.showHint(cm, CodeMirror.hint.anyword);
        };
        sincapp.codeEditor = CodeMirror.fromTextArea(document.getElementById("editor-code"), {lineNumbers: true, matchBrackets: true, extraKeys: {"Ctrl-Space": "autocomplete"}, mode: mode});
        scriptPanel.getValue = function () {
            return sincapp.codeEditor.getValue();
        };
        scriptPanel.setValue = function (newName,oldName) {

           var newValue= sincapp.codeEditor.getValue().replace(newName,oldName);

           $('#editor:nth-child(1)').html(newValue);
        };

        return scriptPanel;
    }

因为您调用的是html而不是val 而不是$'editor:nth-child1'.htmlnewValue;
说$'editor:nth-child1'.valnewValue

这不是关于文本区,而是关于CodeMirror,我的错误。实际上,这对我来说非常简单:

 sincapp.codeEditor.setValue(newValue)

试试这样的

var newValue = sincapp.codeEditor.getDoc().setValue(newName);