相关疑难解决方法(0)

如何获取Codemirror textarea的值

我正在使用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)

javascript codemirror

60
推荐指数
4
解决办法
4万
查看次数

如何从 Cypress 清除 Codemirror 编辑器字段

我已经在另一个答案中尝试过类似的方法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})在文本字段上添加新内容和旧内容。

javascript codemirror e2e-testing cypress

2
推荐指数
1
解决办法
1558
查看次数

标签 统计

codemirror ×2

javascript ×2

cypress ×1

e2e-testing ×1