[英]How to clear the WYSIWYG mathquill editor?
在此地址: http : //jenseng.github.io/mathquill/demo.html
我打开Web控制台并输入:
$(document.getElementsByClassName("mathquill-editor")).mathquill('latex','')
它成功清除了页面底部的WYSIWYG编辑器,但随后我无法输入其他任何内容。它还将光标从左侧移动到右侧。 有什么想法如何使文本框可编辑并将光标再次移到左侧?
发生这种情况似乎是因为当您运行.mathquill('latex', info)
,它还会删除使用编辑器所需的元素。 编辑器( $('.mathquill-editor')
)需要其前2 $('.mathquill-editor')
才能运行,其余部分是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');
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');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.