如何清除所见即所得的数学羽毛笔编辑器



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

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

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

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

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

清除它的主要方法如下:

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

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

杰奎里

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');
或者,

您可以知道希望编辑器执行哪些击键。

mathquillEditor.focus();

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

最新更新