Last active
December 10, 2015 06:38
-
-
Save marvin1023/4395713 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//获取元素 | |
var $ = { | |
byId: function(id) { | |
return typeof id == "string" ? document.geteleentById(id) : id; | |
}, | |
byClass: function(cls, parent, tag) { | |
var parent = parent || document; | |
var tag = tag || "*"; | |
if(parent.geteleentsByClassName) { | |
return parent.geteleentsByClassName(cls); | |
} else { | |
var aClass = []; | |
var reg = new RegExp("(^| )" + cls + "( |$)"); | |
var aele = this.byTag(tag, parent); | |
for(var i = 0, len = aele.length; i < len; i++) { | |
reg.test(aele[i].className) && aClass.push(aele[i]); | |
} | |
return aClass; | |
} | |
}, | |
byTag: function(ele, obj) { | |
return(obj || document).geteleentsByTagName(ele); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment