如何清除WYSIWYG mathquill编辑器?

时间:2022-09-11 20:51:24

At this address: http://jenseng.github.io/mathquill/demo.html

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

I open a web console and type:

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

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

It successfully clears the WYSIWYG editor at the bottom of the page, but then I can't type anything else in. It also moves the cursor from the left side to the right side. Any ideas how to make the text box editable and move the cursor to the left again?

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

2 个解决方案

#1


2  

This seems to happen because when you run .mathquill('latex', info), it also removes the necessary elements to use the editor. The editor ($('.mathquill-editor')) needs its first 2 children to be able to function, the rest are part of mathquill.

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

The main way to clear it is the following:

清除它的主要方法如下:

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

But I will also include a more dynamic way, in case the above code doesn't work on another website and/or the classname isn't the same.

但是,如果上述代码在其他网站上不起作用和/或类名不相同,我还将包含一种更动态的方式。

JQuery

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

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

#2


0  

Alternatively you can tell which keystrokes you want the editor to perform.

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

mathquillEditor.focus();

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

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

#1


2  

This seems to happen because when you run .mathquill('latex', info), it also removes the necessary elements to use the editor. The editor ($('.mathquill-editor')) needs its first 2 children to be able to function, the rest are part of mathquill.

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

The main way to clear it is the following:

清除它的主要方法如下:

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

But I will also include a more dynamic way, in case the above code doesn't work on another website and/or the classname isn't the same.

但是,如果上述代码在其他网站上不起作用和/或类名不相同,我还将包含一种更动态的方式。

JQuery

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

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

#2


0  

Alternatively you can tell which keystrokes you want the editor to perform.

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

mathquillEditor.focus();

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

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