刷新页面上的Javascript而不刷新HTML [英] Refreshing Javascript on the page without refreshing HTML
问题描述
关于我的问题的一点背景。
我正在更新当前显示HTML的div中的MathML。第一次加载页面时,如果运行MathJax脚本并完美显示所有MathML。
当我点击预览更改时,一个按钮将在文本区域中进行当前更改并将它们显示在预览div上,MathML将消失。
我认为问题在于刷新div不会触发MathJax脚本。我已经尝试了$ .getScript(),并且我试图每次单击预览更改按钮时使用document.createElement(脚本)添加脚本,但所有这些都无济于事。
<我希望能有人帮助我。
预先感谢您。
MathJax.Hub.Queue([Typeset ,MathJax.Hub]);
阅读更多关于如何在此处使用它的说明: http://docs.mathjax.org/en/v1.1-latest/typeset.html
例如, MathJax.Hub.Queue([Typeset,MathJax.Hub,previewdiv]);
会使用jQuery调用更新其内容后,使用ID previewdiv
重新呈现HTML元素的更新内容。
A little context on my problem. I am updating the MathML in this div that is currently displaying HTML. When I load the page the first time, if runs the MathJax script and displays all the MathML perfectly. When I click "Preview Changes", a button that takes the current changes made in a text area and displays them on the preview div, the MathML disappears.
I think problem here is that refreshing the div doesn't trigger the MathJax script. I have tried $.getScript(), and I tried adding a script using document.createElement(script) everytime the preview changes button is clicked, but all that to no avail.
I was hoping if someone could help me w/ this.
Thank you in advance.
MathJax.Hub.Typeset()
is the JavaScript command that can re-render the math content within your page or within individual elements that have been updated by current changes. If you are sure that all typesetting is finished, then you can call it directly, but in general it is good to use the safe way to call it, like this MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
Read more instructions for how to use it here: http://docs.mathjax.org/en/v1.1-latest/typeset.html
For instance, MathJax.Hub.Queue(["Typeset",MathJax.Hub,"previewdiv"]);
would re-render the updated contents of the HTML element with an ID of previewdiv
after you have updated its contents using your jQuery call.
这篇关于刷新页面上的Javascript而不刷新HTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!