Javascript Jquery替代DOMSubtreeModified

Javascript Jquery替代DOMSubtreeModified,javascript,jquery,Javascript,Jquery,我有以下Javascript/Jquery代码: <script type="text/javascript"> function ChangeMathOnPage() { MathJax.Hub.Queue(["Typeset",MathJax.Hub]); } $('.markdownx-preview').each(function(){

我有以下Javascript/Jquery代码:

       <script type="text/javascript">
            function ChangeMathOnPage() {
                MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
            }

            $('.markdownx-preview').each(function(){
                $(this).on('DOMSubtreeModified', ChangeMathOnPage);
            });
        </script>

函数ChangeMathOnPage(){
Queue([“Typeset”,MathJax.Hub]);
}
$('.markdownx预览')。每个(函数(){
$(this).on('domsubtreemedited',ChangeMathOnPage);
});
这是我的工作。然而,正如所解释的,使用 不推荐使用DOMSubtreeModified

对于不熟悉Javascript/Jquery的人,请解释如何将相同的逻辑转换为不推荐使用的代码

试试这个:

// Select the node that will be observed for mutations
var targetNode = document.getElementById('some-id');

// Options for the observer (which mutations to observe)
var config = { attributes: true, childList: true };

// Callback function to execute when mutations are observed
var callback = function(mutationsList) {
    for(var mutation of mutationsList) {
        if (mutation.type == 'childList') {
            console.log('A child node has been added or removed.');
        }
        else if (mutation.type == 'attributes') {
            console.log('The ' + mutation.attributeName + ' attribute was modified.');
        }
    }
};

// Create an observer instance linked to the callback function
var observer = new MutationObserver(callback);

// Start observing the target node for configured mutations
observer.observe(targetNode, config);

// Later, you can stop observing
observer.disconnect();

来源:

尝试按照上的“示例用法”,请看这里。。。可能与您有关: