11

入力中にこの mathjax の例をライブ プレビューに変更するにはどうすればよいですか? 現在、Enter キーを押した後にのみ結果が表示されます。質問を入力するときに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>
4

3 に答える 3

5

onchangetryonkeypressまたはを使用する代わりにonkeyup

onchangeフィールドを離れたときにのみトリガーされますが、他のものは(明らかに)キーストロークごとに発生します。

于 2011-10-28T06:14:19.300 に答える
1

onchange他のブラウザほど頻繁にまたは効率的にイベントを発生させないInternetExplorerを使用していると思われます。

MathJaxの例のバージョンには、IEをより適切に処理するためのより多くのコードが含まれています。詳細については、そこにあるソースコードを参照することをお勧めします。

于 2012-04-01T23:34:02.090 に答える