2014-09-28 46 views
3

我有一個包含textarea的頁面。用戶將在其中輸入mathML,當用戶點擊輸出按鈕時,MathML應該呈現並顯示在textarea下。但渲染沒有發生。 Textarea可能包含多個用於渲染的mathml代碼。MathML沒有呈現並顯示在textarea下面

下面是我用過的代碼。

<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
    <script type="text/javascript" src="file:/P:/MathJax/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script> 
</head> 
<body> 
     <h3>MathML Previewer</h3> 

     Paste your MathML:<br> 
      <textarea id="myMath" style="resize: none; height:250px; width:850px"> 
     </textarea> 

      <button type="button" onclick="myclear()">Reset</button> 
      <p>Click the button to get output</p> 
      <button type="button" onclick="myFunction()">Output</button> 
      <div id="demo"> 
      </div> 

      </div> 
      <script> 
       function myFunction() { 

       var x = document.getElementById("myMath").value; 
       document.getElementById("demo").innerHTML = x; 
       } 
      </script> 
      <script> 
       function myclear() { 
       var x = document.getElementById("myMath").value =' '; 
       //document.getElementById("demo").innerHTML = x; 

       } 
      </script> 

    </body> 
</html> 
+0

您是否使用'file'方案運行該頁面? – Oriol 2014-09-28 15:12:12

+0

是的,我已經毀了,但沒有提到,因爲我已經提到。 – 2014-09-28 15:29:56

+0

你在找什麼輸出?當我測試你的代碼時,它似乎工作正常。然而,從搜索來看,只有Firefox和Safari支持正確渲染MathML,而這正是我在我的計算機上看到的在IE,Firefox和Chrome上測試代碼的情況,只有Firefox正確地渲染了它。 – peterjb 2014-09-28 16:50:43

回答

2

當客戶端腳本更改時,不應期望MathJax處理頁面。來請求用於這樣的處理中,添加以下執行的改變的代碼之後,在這裏的功能myFunction末尾:

MathJax.Hub.Typeset(); 

更經濟,使得單個元件使用代碼只要處理:

MathJax.Hub.Typeset("demo"); 

請參閱MathJax文檔第Modifying Math on the Page頁。

+0

for without namespace它工作正常,但如果我包含名稱空間如m:和/或mml:則渲染不會發生。 – 2014-09-29 05:44:23

+0

爲了使命名空間得到正確處理,您需要在''標籤中聲明它們。例如,''。如果你想同時處理'm:'和'mml:',則將兩者都作爲namsepaces添加。 – 2014-09-29 14:41:44

+0

儘管我在標記中添加了名稱空間聲明,但仍然沒有發生渲染。 – 2014-09-29 19:08:17