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

ただし、上記のコードが別の Web サイトで機能しない場合や、クラス名が同じでない場合に備えて、より動的な方法も含めます。

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 に答える