How to get the value of Codemirror textarea

匿名 (未验证) 提交于 2019-12-03 02:47:02

问题:

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();



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!