ITeye博客

extjs源码分析-005(Ext.getDom,Ext.getBody)

y1d2y3xyz · 2011-02-08 00:22 · Extjs · Web前端 · Markdown


var DOC = document;
//获取DOM节点对象
getDom : function(el, strict){//el-->id 或者 html节点,strict-->是否只支持ID属性(ie下IE的name属性也能获取)获取节点对象
            if(!el || !DOC){
                return null;
            }
            if (el.dom){
                return el.dom;
            } else {
                if (typeof el == 'string') {//如果传的参数是字符串,就当是ID处理
                    var e = DOC.getElementById(el);
                    // IE returns elements with the 'name' and 'id' attribute.
                    // we do a strict check to return the element with only the id attribute
                    if (e && isIE && strict) {
                        if (el == e.getAttribute('id')) {
                            return e;
                        } else {
                            return null;
                        }
                    }
                    return e;
                } else {
                    return el;
                }
            }
        },

getBody : function(){//获取文档的body节点对象
     return Ext.get(DOC.body || DOC.documentElement);
}

评论(0)

暂无评论。

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