获取codemirror的当前内容
我想使用 php 脚本保存 codemirror 编辑器的当前内容。我使用以下代码希望当单击按钮时当前内容将传递到 php 脚本。下面的脚本已经过编辑和运行。
var test = code.getValue();
但这并不反映编辑器的变化。
<script language = "Javascript">
function saveData() {
var test = editor.getValue();
new Ajax.Request('savedata.php', {
method: 'post',
parameters: {
test: test,
}
});
}
</script>
编辑器是使用以下方式构建的: ;
<script>
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
lineNumbers: true,
lineWrapping: true,
extraKeys: {"F11": toggleFullscreenEditing, "Esc": toggleFullscreenEditing},
onBlur: function(){editor.save()}
});
非常感谢任何意见或建议。谢谢。
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 comments or suggestions are highly appreciate. Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
请注意,CodeMirror 的事件 api 已更改(请参阅 CodeMirror 文档),
因此上面的内容应该是这样的喜欢:
Note that the CodeMirror's event api has changed (see CodeMirror doc)
So the above should be something like:
使用编辑器的最后一个代码...您必须放入一个函数并在更改文本区域后调用它 - 可能使用
OnBlur=""
。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: