码迷,mamicode.com
首页 > 其他好文 > 详细

dom元素改变监听

时间:2017-05-11 19:45:01      阅读:163      评论:0      收藏:0      [点我收藏+]

标签:dom   ldl   func   observer   pre   ons   node   nec   each   

 function domChange(domId, callback) {
            // select the target node
            var target = document.getElementById(domId);
            // create an observer instance
            var observer = new MutationObserver(function (mutations) {
                mutations.forEach(function (mutation) {
                    callback();
                });
            });
            // configuration of the observer:
            var config = { attributes: true, childList: true, characterData: true };
            // pass in the target node, as well as the observer options
            observer.observe(target, config);
            // later, you can stop observing
            //observer.disconnect();
        }

 

dom元素改变监听

标签:dom   ldl   func   observer   pre   ons   node   nec   each   

原文地址:http://www.cnblogs.com/gaocong/p/6842187.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!