1.在html页面上添加
<script type="text/javascript"
src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
tex2jax: {inlineMath: [['$','$'], ['\(','\)']]}
});
</script>
把要显示的公式先拼成一个字符串
var gongshi="<div>$δ="+sub1(xishu.coef_1)+"H_0+"+sub1(xishu.coef_2)+"H_0^2+"+sub1(xishu.coef_3)+"H_0^3+"+sub1(xishu.coef_4)+"\\bar H_{1-2}+"+sub1(xishu.coef_5)+"\\bar H_{3-7}" + "+"+sub1(xishu.coef_6)+"\\bar H_{8-15}+"+sub1(xishu.coef_7)+"\\bar H_{16-30}+"+sub1(xishu.coef_8)+"\\Delta H+"+sub1(xishu.coef_9)+"\\Delta H^2+"+sub1(xishu.coef_10)+"\\Delta H^3 \\\\\\\\" +
"+"+sub1(xishu.coef_11)+"T_0+"+sub1(xishu.coef_12)+"T_{1-7}+"+sub1(xishu.coef_13)+"T_{8-30}+"+sub1(xishu.coef_14)+"T_{31-60}+"+sub1(xishu.coef_15)+"T_{61-120}+" +""+sub1(xishu.coef_16)+"\\cos {2πt \\over 365}+"+sub1(xishu.coef_17)+"\\sin{2πt \\over 365}"+sub1(xishu.coef_18)+"\\cos {4πt \\over 365}+"+sub1(xishu.coef_19)+"\\sin {4πt \\over 365} "+ "+"+sub1(xishu.coef_20)+"\\cos {6πt \\over 365}\\\\\\\\" +
"+"+sub1(xishu.coef_21)+"\\sin {6πt \\over 365}+"+sub1(xishu.coef_22)+"\\cos {8πt \\over 365}+"+sub1(xishu.coef_23)+"\\sin{8πt \\over 365}+"+sub1(xishu.coef_24)+"\\cos{10πt \\over 365}" + "+"+sub1(xishu.coef_25)+"\\sin{10πt \\over 365}" +"+"+sub1(xishu.coef_26)+"\\cos{12πt \\over 365}+"+sub1(xishu.coef_27)+"\\sin{12πt \\over 365}" +" +"+sub1(xishu.coef_28)+"\\cos{14πt \\over 365}+"+sub1(xishu.coef_29)+"\\sin{14πt \\over 365}" +"+"+sub1(xishu.coef_30)+"\\cos{16πt \\over 365}\\\\\\\\" +
"+"+sub1(xishu.coef_31)+"\\sin{16πt \\over 365}+"+sub1(xishu.coef_32)+"\\cos{18πt \\over 365}+"+sub1(xishu.coef_33)+"\\sin{18πt \\over 365}+"+sub1(xishu.coef_34)+"R_0" + "+"+sub1(xishu.coef_35)+"\\bar R_{1-2}" +"+"+sub1(xishu.coef_36)+"\\bar R_{3-7}+"+sub1(xishu.coef_37)+"\\bar R_{8-15}+"+sub1(xishu.coef_38)+"\\bar R_{16-30}+"+sub1(xishu.coef_39)+"θ+"+sub1(xishu.coef_40)+"\\lnθ+"+sub1(xishu.intercept_)+"$</div>";
$('#gongshi').html(gongshi);
MathJax.Hub.Queue(["Typeset", MathJax.Hub]);
特别注意: 拼接完要刷新一下否则不好用 MathJax.Hub.Queue(["Typeset", MathJax.Hub]);
效果如下
image.png
网友评论