dom监听事件class

layui.use(['layer', 'form'], function(){
                var layer = layui.layer
                    ,form = layui.form;
                var $ = layui.jquery;


                function classEvent(className,searchClassName,callback)
                {
                    var options={
                        attributes:true,//观察node对象的属性
                        attributeFilter:['class']//只观察class属性
                    };

                    var mb=new MutationObserver(function(mutationRecord,observer){
                        var targetClassName = mutationRecord[0].target.className;
                        if( targetClassName.indexOf(searchClassName) != -1)
                        {
                            //检查到包含此class
                            callback(mutationRecord);
                        }

                    });

                    $("body").bind('DOMNodeInserted', function(e) {
                        var target= $(className);
                        if(target.length > 0)
                        {
                            for(var i = 0;i<target.length;i++)
                                mb.observe(target.get(i),options);
                        }
                    });
                }

                classEvent(".layui-form-checkbox","layui-form-checkbox",function(m){
                    //console.info(m[0].target);
                    fixCols();
                });

            });

 

posted @ 2018-10-15 12:56  彭成刚  阅读(257)  评论(0编辑  收藏  举报