开始慢慢从JQUERY再转回到纯JS。。。
代码
//原理: 用document.getElementsByTagName('*');来获取所有元素,然后取得相同Class的元素。
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;
}
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;
}
// 原来class为showye的全去掉
var XX = getElementsByClassName('shouye');
for (var i = 0; i < XX.length; i++) {
XX[i].className = "";
}
for (var i = 0; i < XX.length; i++) {
XX[i].className = "";
}