ITeye博客

清空dom源码解析

小丑鱼0703 · 2015-04-04 17:06 · jquery · Web前端 · Markdown

jquery中empty()是采用逐个移除子元素实现的 zepto中empty()是采用直接innerHtml=''实现的

一起来看一下:


empty:function(){
        var elem,i=0;
        for(;(elem = this[i]) != null; i++) {
                if(elem.nodeType === 1){
                                             jQuery.cleanData(elem.getElementsByTagName("*"));

                 }
                 while(elem.firstchild){
                              elem.removeChild(elem.firstchild);
                 }
        }
}


empty:function(){
        return  this.each(function(){
                this.innerHtml=''
        })
}

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。