How to get the value of Codemirror textarea

痴心易碎 提交于 2019-12-02 19:55:37

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).

Siddhartha Mukherjee

This works fine for me.

editor.getValue()

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

Version: 5

According to the Documentation, you need now to do it like:

doc.getValue(?separator: string) → string

So in this example:

editor.getDoc().getValue("\n")

I know you are using textarea but I hope this code will be useful for others! I have this problem but with article tag, and this is my solution to getting all codes with jquery:

res_array = []
$.each($('article.code-draft span[role="presentation"]'), function(){
    res_array.push($(this).text())
});
console.log(res_array.join('\n'))
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!