반응형
Codemirror 텍스트 영역의 가치를 얻는 방법
textarea에 Codemirror의 플러그인을 사용하고 있지만 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);
}
오류가 표시됩니다.
editor.getCode() is not a function.
getValue()
대신을 사용해보십시오 getCode()
.
선택적 인수를 getValue (separator)에 전달하여 줄을 구분하는 데 사용할 문자열을 지정합니다 (기본값은 \n
).
이것은 나를 위해 잘 작동합니다.
editor.getValue()
your_editor_instace.getValue (); 사용
codemirror에 이름이 getCode () 인 함수가 없기 때문에 제대로 작동합니다.
값을 설정하려면 your_editor_instance.setValue ();
버전 : 5
문서 에 따르면 이제 다음과 같이해야합니다.
doc.getValue(?separator: string) → string
따라서이 예에서 :
editor.getDoc().getValue("\n")
나는 당신이 사용하고 있다는 것을 알고 textarea
있지만이 코드가 다른 사람들에게 유용하기를 바랍니다! 이 문제가 있지만 article
태그가 있으며 이것은 jquery로 모든 코드를 얻는 방법입니다.
res_array = []
$.each($('article.code-draft span[role="presentation"]'), function(){
res_array.push($(this).text())
});
console.log(res_array.join('\n'))
참고 URL : https://stackoverflow.com/questions/10285301/how-to-get-the-value-of-codemirror-textarea
반응형
'IT TIP' 카테고리의 다른 글
Node.js 프로젝트 문서화 (0) | 2020.12.11 |
---|---|
2 개의 "float"를 사용하여 "double"을 에뮬레이션 (0) | 2020.12.11 |
PDF 문서의 페이지 수 얻기 (0) | 2020.12.11 |
Ruby에서 예외를 포착 한 후 다시 발생 (동일한 예외) (0) | 2020.12.11 |
Mac에 sshpass를 설치하는 방법은 무엇입니까? (0) | 2020.12.10 |