MathJax在Jquery .click事件中不起作用

时间:2018-02-23 18:48:24

标签: javascript jquery html mathjax

Jquery MathJax内部的

.click事件不起作用,但在该功能之外。

运行代码段以查看效果。



$('#math').click(function(e){
e.preventDefault();
$("#result").html("$$ MathJax inside .click event doesn't work $$");
});
//outside .click event
$("#Outside").html("$$ \\frac{d}{dx}\\left(2x^2\\right)=\\:4x $$");

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.2/MathJax.js?config=TeX-MML-AM_CHTML'></script>


<button id="math"  type="submit" >
<b>ShowMathjax On click</b>
</button>
<span id="result"></span>
<div style="padding:10%;">
MathJax Outside .click event works:
<span id="Outside"></span>
</div>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:1)

MathJax仅在加载页面时运行一次。如果更改页面内容以包含更多数学,则必须手动调用MathJax以重新处理数学运算。有关详细信息,请参阅MathJax Documentation

在您的情况下,您需要将呼叫排队到Mail::send();以处理修改后的内容。请参阅下面的示例。 (另请注意,您需要将javascript字符串文字中的反斜杠加倍,以便在数学中包含反斜杠。)

&#13;
&#13;
    from sklearn.linear_model import LogisticRegression
    from sklearn.tree import DecisionTreeClassifier

    clf1 = LogisticRegression(penalty='l2',C=1e9) # very weak l2-regularization
    clf2 = DecisionTreeClassifier(max_depth=3)

    import numpy as np

    y = np.zeros(1000)
    y[500:] = 1.

   #should change this
    x1 = np.zeros((1000,2))

    x2 = np.zeros((1000,2))


    x3 = np.zeros((1000,2))

    clf_names = ['LogReg', 'DT']
    clfs      = [clf1,     clf2]
    ​
    for dataset in [x1,x2,x3]:
        for i in range(2):
            print (clf_names[i], round(clfs[i].fit(dataset,y).score(dataset,y),3))
    LogReg 0.5
    DT 0.5
    LogReg 0.5
    DT 0.5
    LogReg 0.5
    DT 0.5
&#13;
MathJax.Hub.Typeset()
&#13;
&#13;
&#13;