Nit*_*bra 60 javascript codemirror
我正在使用Codemirror的textarea插件,但我无法检索textarea的值.
码:
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
lineNumbers: true,
matchBrackets: true,
mode: "text/x-csrc"
});
function showCode()
{
var text = editor.mirror.getCode();
alert(text);
}
Run Code Online (Sandbox Code Playgroud)
它显示错误:
editor.getCode() is not a function.
Run Code Online (Sandbox Code Playgroud)
Eri*_*ski 80
尝试使用getValue()而不是getCode().
将可选参数传入getValue(分隔符)以指定用于分隔行的字符串(默认值为\n).
在版本 6 中,假设您有EditorViewin 变量editor,那么您可以:
editor.state.doc.toString()
Run Code Online (Sandbox Code Playgroud)
使用 your_editor_instance.getValue();
它会正常工作,因为getCode()CodeMirror 中没有以名称命名的函数。
用于设置值使用 your_editor_instance.setValue();
| 归档时间: |
|
| 查看次数: |
42599 次 |
| 最近记录: |