function getClass(classname){
if (document.getElementsByClassName) {
//使用现有方法
return document.getElementsByClassName(classname);
}else{
//定义一个数组放classname
var results = new Array();
//获取所有节点元素
var elem = document.getElementsByTagName("*");
for (var i = 0; i < elem.length; i++) {
if (elem[i].className.indexOf(classname) != -1) {
results[results.length] = elem[i];
}
}
return results;
}
}
JS原生获取class对象(getElementsByClassName)
最新推荐文章于 2024-09-07 03:19:38 发布