2010-09-28 65 views
2

我正嘗試使用MathJax將文本轉換爲數學,同時使用textarea字段進行打字。但是,當我將輸入的文本發送到數據庫以通過php文件檢索文本回原始文件時,我無法讓MathJax將文本轉換爲類似LaTeX的符號。如何動態加載MathJax?

這是(使用jQuery)的主要部分:

$(document).ready(function(){ 
$('textarea').keydown(function(){ 
    dynamic(); \\ A function described in MathJax documentation to load dynamically 
    var text = $('textarea').val(); 
    $.post('process.php',{ input: text }); 
    $("#unload").load('fetch.php'); 
    }); 
}); 

其中動態()被定義爲(從Loading MathJax Dynamically截取):

function dynamic(){var script = document.createElement("script"); 
script.type = "text/javascript"; 
script.src = "http://miql.zxq.net/MathJax/MathJax.js"; 
var config = 'MathJax.Hub.Config({ config: "MathJax.js" }); ' + 
'MathJax.Hub.Startup.onload();'; 
if (window.opera) {script.innerHTML = config} 
else {script.text = config} 
document.getElementsByTagName("head")[0].appendChild(script); 
}; 

此外,我有楷書到MathJax哪些工作正常,但使用onload事件。

我想我錯了指令動態加載MathJax。什麼是正確的方法來做到這一點?任何幫助將不勝感激。

回答