我正在使用Codemirror的textarea插件,但我无法检索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);
}
Run Code Online (Sandbox Code Playgroud)
它显示错误:
editor.getCode() is not a function.
Run Code Online (Sandbox Code Playgroud) 我已经在另一个答案中尝试过类似的方法How to type using cypress .type() inside the codemirror editor?
如果有帮助的话,这是我正在 Cypress 上工作的网站https://testing-playground.com/
// CodeMirror's editor doesn't let us clear it from the
// textarea, but we can read the Window object and then
// invoke `setValue` on the editor global
cy.window().then(win => {
win.editor.setValue("")
})
Run Code Online (Sandbox Code Playgroud)
我遇到的问题是,当我尝试实现这个时,我得到了undefined编辑器。我尝试深入研究 Window 对象,但找不到任何类似于 Codemirror 编辑器的内容。.clear({force: true})在任何其他 Codemirror 元素上运行都不会产生任何结果,只会.type({force: true})在文本字段上添加新内容和旧内容。