我最近開始在我的應用程序中使用MathJax,並使用JQuery嘗試編寫直觀/構造邏輯的編輯器。我面臨的問題是無論何時加載頁面,我使用JQuery注入MathML,它不能正確呈現。下面的代碼使用MathJax和JQuery插入MathML
<math display="block" id="mathml-derivation">
<mrow class="beginning">
</mrow>
</math>
這是JavaScript
setTimeout(function() {
console.log("Started");
var $frac = document.createElement('mfrac');
$frac.innerHTML = '<mrow id="children' + parseInt(1) + '" class="conclusion">\
<mrow>\
<mi>b</mi>\
</mrow>\
</mrow>\
<mrow class="assumption">\
<mo>' + "\u22A2" + '</mo>\
<mrow class="goal clickable">\
<mi>a</mi>\
</mrow>\
</mrow>';
$("#mathml-derivation").append($frac);
console.log($frac);
MathJax.Hub.Typeset("mathml-derivation");
}, 1000);
我不能確定是什麼問題。我有一個setTimeout函數的原因是爲了確保它在頁面加載後至少執行一秒。當我立即加載或通過事件加載時,MathML無法正確渲染。我跟在StackOverflow上的一些其他帖子,它說使用'.Typeset'函數,但它不能正常工作。
作爲最後一點,我使用Chrome開發,並且我正在使用MathJax來兼容。
你能分享一個完整的,獨立的例子作爲嵌入式片段嗎? –
@PeterKrautzberger感謝您的回覆,這裏是一個jsfiddle https://jsfiddle.net/rmqj0pwv/ ...注意,如果您將setTimeout從1000更改爲0,那麼它的工作原理,否則它不會 – Ysrninja