admin管理员组文章数量:1331619
I'd like to save the current content of a codemirror editor using a php script. I used the following codes in the hope when clicking on a button the current content will be passed to the php script. The scripts below has been edited and worked.
var test = code.getValue();
but this does not reflect the change in the editor.
<script language = "Javascript">
function saveData() {
var test = editor.getValue();
new Ajax.Request('savedata.php', {
method: 'post',
parameters: {
test: test,
}
});
}
</script>
The editor is constructed using: ;
<script>
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
lineNumbers: true,
lineWrapping: true,
extraKeys: {"F11": toggleFullscreenEditing, "Esc": toggleFullscreenEditing},
onBlur: function(){editor.save()}
});
Any ments or suggestions are highly appreciate. Thanks.
I'd like to save the current content of a codemirror editor using a php script. I used the following codes in the hope when clicking on a button the current content will be passed to the php script. The scripts below has been edited and worked.
var test = code.getValue();
but this does not reflect the change in the editor.
<script language = "Javascript">
function saveData() {
var test = editor.getValue();
new Ajax.Request('savedata.php', {
method: 'post',
parameters: {
test: test,
}
});
}
</script>
The editor is constructed using: ;
<script>
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
lineNumbers: true,
lineWrapping: true,
extraKeys: {"F11": toggleFullscreenEditing, "Esc": toggleFullscreenEditing},
onBlur: function(){editor.save()}
});
Any ments or suggestions are highly appreciate. Thanks.
Share Improve this question edited Jan 1, 2012 at 19:20 Zhiyong Zhang asked Jan 1, 2012 at 2:48 Zhiyong ZhangZhiyong Zhang 531 silver badge4 bronze badges3 Answers
Reset to default 3Note that the CodeMirror's event api has changed (see CodeMirror doc)
So the above should be something like:
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
lineNumbers: true,
lineWrapping: true,
extraKeys: {"F11": toggleFullscreenEditing, "Esc": toggleFullscreenEditing},
});
editor.on("blur": function(){editor.save();});
The last code with editor ... You have to put in a function and call it after changing the text area - maybe with OnBlur=""
.
this will also work:
document.querySelector('.CodeMirror').CodeMirror.setValue('some text');
本文标签: javascriptget the current content of codemirrorStack Overflow
版权声明:本文标题:javascript - get the current content of codemirror - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742243249a2438967.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论