我有以下 Javascript/Jquery 代码:
<script type="text/javascript">
function ChangeMathOnPage() {
MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
}
$('.markdownx-preview').each(function(){
$(this).on('DOMSubtreeModified', ChangeMathOnPage);
});
</script>
这是我的工作。然而,正如解释的here , 用于 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();
关于javascript - DOMSubtreeModified 的 Jquery 替代品,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50107004/