gpt4 book ai didi

javascript - 创建多个代码镜像并将值保存到文本区域

转载 作者:行者123 更新时间:2023-12-02 16:58:43 26 4
gpt4 key购买 nike

我在博客中使用codemirror,代码如下:

var codeJs = document.getElementsByClassName("code-js");
var editor = [];

for (var i=0; i<codeJS.length; i++){
editor[i] = CodeMirror.fromTextArea(codeJS[i], {
lineNumbers: true,
matchBrackets: true,
autoCloseBrackets: true
});
// Save the value of every codemirror to the textarea
editor[i].on("blur", function() {editor[i].save()});
}

我将上面的代码用于多个代码镜像,我想将每个代码镜像的值保存到它们自己的文本区域,它工作正常,除了这一行:

editor[i].on("blur", function() {editor[i].save()});

有人能找出我的代码有什么问题吗?

最佳答案

试试这个editor[i].on("blur", function(codeMirror) {codeMirror.save()});

关于javascript - 创建多个代码镜像并将值保存到文本区域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25955509/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com