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()
转载于:https://www.cnblogs.com/zhangshun/p/6120476.html