可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
I am using Codemirror's plugin for textarea but I am not able to retrieve the value of textarea.
Code:
var editor = CodeMirror.fromTextArea(document.getElementById("code"), { lineNumbers: true, matchBrackets: true, mode: "text/x-csrc" }); function showCode() { var text = editor.mirror.getCode(); alert(text); }
It is showing the error:
editor.getCode() is not a function.
回答1:
Try using getValue()
instead of getCode()
.
Pass in an optional argument into getValue(separator) to specify the string to be used to separate lines (the default is \n
).
回答2:
This works fine for me.
editor.getValue()
回答3:
use your_editor_instace.getValue();
It will work fine because there is no function named with the name as getCode() in codemirror.
for setting value use your_editor_instance.setValue();