我試圖動態更改textarea的字符串值。在我的代碼setValue函數應該這樣做,但每當我嘗試,文本區域正在改變,但後來不可編輯。 什麼可能導致問題?JQuery如何更改CodeMirror中textarea的字符串值
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;
}