[英]How can I render MathJax when some element is clicked?
我有一個輸入字段,我在其中鍵入 LaTeX 命令,當我單擊按鈕時,這些命令必須呈現為 MathJax。 我使用textContent
屬性將div
元素的內容設置為我在輸入字段中輸入的任何內容。 但是,瀏覽器不會呈現 MathJax 並將div
的內容顯示為 LaTeX 命令。 我認為這可能是因為 MathJax 在文檔加載時被渲染。 單擊按鈕時,有什么方法可以渲染 MathJax? 我不了解 jquery 或任何其他 JavaScript 庫。 是否有某種方法可以在不使用它們的情況下做到這一點,或者是否有必要使用它們?
<head> <script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_CHTML"> <!-- The source is used to render mathjax --> function dispMJ() { var a = document.getElementById("mj").value; document.getElementById("disp").textContent = a; } </script> </head> <body> <input type="text" id="mj"> <input type="button" value="render MJ" onclick="dispMJ();"> <div id="disp"></div> </body>
你應該使用 QUEUE 告訴 MathJax 重新渲染 div,在這里看一個完整的例子http://codepen.io/damianfabian/pen/EgWEpv?editors=1000
UpdateMath = function () {
var TeX = document.getElementById("MathInput").value;
QUEUE.Push(["Text",math,"\\displaystyle{"+TeX+"}"]);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.