复制代码 代码如下:
function getElementsByClassName(n) {
var classElements = [],allElements = document.getElementsByTagName('*');
for (var i=0; i< allElements.length; i++ )
{
if (allElements[i].className == n ) {
classElements[classElements.length] = allElements[i];
}
}
return classElements;
}
var redClassElements = getElementsByClassName('aa');
for (var i=0; i<redClassElements.length; i++) {
//do something
}
时间: 2024-11-03 01:39:34