突变观察者未显示元素属性更改

问题描述

因此,我有一个元素正在加载一些被修饰的内容,尽管单击更改可以很好地触发来自变异观察器的回调函数,但我需要的属性更改不起作用。 代码看起来像这样:

function addobserverIfDesirednodeAvailable() {
    var detectIfhasPostData = document.querySelector(".watcher");
    if (!detectIfhasPostData) {
        window.setTimeout(addobserverIfDesirednodeAvailable,1000);
        return;
    }
    var options = {
        attributes: true,attributeFilter: ["post-loaded"]
    };

    ourObserver.observe(document.querySelector("#postAppend"),options);
}

var ourObserver = new MutationObserver(function(mutationList) {
    mutationList.forEach(mutation => {
        switch (mutation.type) {
            case "childList":
              console.log("This one works"); 

                break;
            case "attributes":
                // I am trying to get this working 
            console.log(mutation.attributeName);          
        }
    });

});

//and when the ajax is fired: 
$("#" + postappendID).attr("post-loaded","1");
//this one changes the element attribute post-loaded to 1 from 0 once the ajax is finished.

这是元素

<div class="flex-grid" id="postAppend" post-loaded="0">

什么可能导致此问题?

谢谢!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)