JS监听页面dom新增方法

    $( document ).ready(function() {
        var observer = new MutationObserver(function(mutations){
            console.log('mutationObserver0')
            mutations.forEach(function(mutation){
                var nodes = mutation.addedNodes;
                for(var i=0,len=nodes.length;i<len;i++){
                    var node = nodes[i];
                    if(node.id==="UserPassword"){
                        console.log('mutationObserver1')
                    }
                }
            });
        });
        observer.observe(document, {
            subtree: true,
            childList: true
        });

        document.addEventListener("DOMNodeInserted",function(e){
            var node = e.target;
            //console.log(node)
            if(node.id==="UserPassword"){
              //  console.log('mutationObserver')
              //  $(document.getElementById('newPwd')).attr('type','text');
              //  $(document.getElementById('enSurePwd')).attr('type','text');
            }
        });

    })
posted @ 2023-07-18 21:33  fly_bk  阅读(248)  评论(0编辑  收藏  举报