復制代碼 代碼如下:
function getByClass(classname){
var nodes = document.getElementsByTagName('*'),
ret=[];
for(var i=0;i<nodes.length;i++){
if(hasClass(nodes[i],classname))
ret.push(nodes[i]);
}
return ret;
}
function hasClass(node,className){
var names = node.className.split(/\s+/);
for(var i=0;i<names.length;i++){
if(names[i]==className)
return true;
}return false;
}