[英]Codemirror editor is not loading content of the textarea
我正在嘗試將CodeMirror應用於我正在使用的這個迷你Web應用程序。 它有兩個有2 textareas。 我想添加CM以獲得更好的可見性,因此我可以編輯一些內容。 到目前為止,我設法應用了Eclipse主題,但該工具不再適用。 似乎CodeMirror沒有將內容復制到textarea。
當我刪除Codemirror js
該工具再次工作。
這是我的JSFiddle
HTML
<textarea id="input" rows="10" cols="80"></textarea>
<textarea id="output" rows="10" cols="80" readonly></textarea>
JS
$('textarea').each(function(index, elem) {
CodeMirror.fromTextArea(elem, {
lineWrapping: true,
mode: "javascript",
theme: "eclipse",
lineNumbers: true,
});
});
在我看來,問題出在http://dean.edwards.name/packer/bindings.js
,確切地說,在以下代碼中:
"#pack-script": {
disabled: false,
onclick: function() {
try {
output.value = "";
if (input.value) {
var value = packer.pack(input.value, base62.checked, shrink.checked);
output.value = value;
message.update();
}
} catch (error) {
message.error("error packing script", error);
} finally {
saveScript.disabled = !output.value;
decodeScript.disabled = !output.value || !base62.checked;
}
}
},
CodeMirror使用內部格式,並將自定義樣式應用於textareas。 因此,textarea的直接方法,例如input.value
將不起作用。 您需要對其進行調整,以便它使用CodeMirror的方法來獲取/設置值,如本指南中 “ 內容操作方法”部分所述。
編輯1:
除了糾正一些語法錯誤,我得到了這個小提琴 。
完成的更改:
editor
函數返回CodeMirror對象,以便可以將其分配給變量。 onclick
方法。 在finally
塊中,有未定義的saveScript
引用和decodeScript
,我評論過。 並使用CodeMirror的getValue()
和setValue()
方法分別獲取/設置值。 如果觀察到,控制台中仍然存在一些錯誤,但這不會妨礙打包器的功能。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.