如何在输入时修改此 mathjax 示例以进行实时预览?现在它只在我按下回车键后显示结果。我想对其进行调整,使其工作方式类似于 stackoverflow/math.stackexchange 在键入问题时显示预览的方式。
<html>
<head>
<title>MathJax Dynamic Math Test Page</title>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
tex2jax: {
inlineMath: [["$","$"],["\\(","\\)"]]
}
});
</script>
<script type="text/javascript"
src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML-full">
</script>
</head>
<body>
<script>
//
// Use a closure to hide the local variables from the
// global namespace
//
(function () {
var QUEUE = MathJax.Hub.queue; // shorthand for the queue
var math = null; // the element jax for the math output.
//
// Get the element jax when MathJax has produced it.
//
QUEUE.Push(function () {
math = MathJax.Hub.getAllJax("MathOutput")[0];
});
//
// The onchange event handler that typesets the
// math entered by the user
//
window.UpdateMath = function (TeX) {
QUEUE.Push(["Text",math,"\\displaystyle{"+TeX+"}"]);
}
})();
</script>
Type some TeX code:
<input id="MathInput" size="50" onchange="UpdateMath(this.value)" />
<p>
<div id="MathOutput">
You typed: ${}$
</div>
</body>
</html>
最佳答案
不要使用 onchange
尝试使用 onkeypress
或 onkeyup
。
onchange
仅在您离开字段时触发,但其他事件(显然)在每次击键时发生。
关于javascript - 实时显示 mathjax 输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7925622/