标签:gen str type name ++ class pre test element
var get = {
byId: function(id) {
return typeof id === "string" ? document.getElementById(id) : id;
},
byClass: function(sClass, oParent) {
var aClass = [];
var reClass = new RegExp("(^| )" + sClass + "( |$)");
var aElem = this.byTagName("*", oParent);
for (var i = 0; i < aElem.length; i++) reClass.test(aElem[i].className) && aClass.push(aElem[i]);
return aClass;
},
byTagName: function(elem, obj) {
return (obj || document).getElementsByTagName(elem)
}
}
调用方法
get.byId() get.byClass() get.byTageName()
标签:gen str type name ++ class pre test element
原文地址:http://www.cnblogs.com/zhangshun/p/6120476.html