0

在这个地址:http: //jenseng.github.io/mathquill/demo.html

我打开一个 Web 控制台并输入:

$(document.getElementsByClassName("mathquill-editor")).mathquill('latex','')

它成功清除了页面底部的 WYSIWYG 编辑器,但是我无法输入任何其他内容。它还将光标从左侧移动到右侧。任何想法如何使文本框可编辑并将光标再次向左移动?

4

2 回答 2

2

这似乎是因为当您运行时.mathquill('latex', info),它还会删除使用编辑器所需的元素。编辑器 ( $('.mathquill-editor')) 需要它的前 2 个子级才能运行,其余的是 mathquill 的一部分。

清除它的主要方法如下:

while ($('.mathquill-editor').children().length > 2)
    $('.mathquill-editor').children()[2].remove();
$('.mathquill-editor').addClass('empty');

但我还将包括一种更动态的方式,以防上面的代码在另一个网站上不起作用和/或类名不一样。

jQuery

function clearEditor(elem) {
    while ($(elem).children().length > 2)
        $(elem).children()[2].remove();
    $(elem).addClass('empty');
}
clearEditor('.mathquill-editor');

纯Javascript

function clearEditor(elem) {
    while (document.querySelector(elem).children.length > 2)
        document.querySelector(elem).children[2].remove();
    document.querySelector(elem).setAttribute('class', document.querySelector(elem).getAttribute('class') + ' empty');
}
clearEditor('.mathquill-editor');
于 2016-06-05T21:16:57.387 回答
0

或者,您可以告诉编辑器执行哪些击键。

mathquillEditor.focus();

mathquillEditor.keystroke('End Shift-Home Del');

于 2017-03-13T01:37:53.403 回答