Javascript JQuery如何更改CodeMirror中textarea的字符串值
我正在尝试动态更改textarea的字符串值。在我的代码setValue函数中,应该这样做,但每当我尝试时,文本区域都会被更改,但之后就不可编辑了。 什么会导致问题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
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);