如何清除WYSIWYG mathquill编辑器?

时间:2016-06-03 19:04:38

标签: javascript jquery wysiwyg mathquill

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

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

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

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

2 个答案:

答案 0 :(得分:2)

这似乎发生了,因为当您运行$('.mathquill-editor')时,它还会删除使用编辑器所需的元素。编辑器(while ($('.mathquill-editor').children().length > 2) $('.mathquill-editor').children()[2].remove(); $('.mathquill-editor').addClass('empty'); )需要前两个孩子才能运行,其余的都是mathquill的一部分。

清除它的主要方法如下:

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

但是,如果上述代码不能在其他网站上运行和/或类名不相同,我也会采用更加动态的方式。

JQuery的

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');

Pure Javascript

{{1}}

答案 1 :(得分:0)

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

mathquillEditor.focus();

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

相关问题