<div id="u">
<div class="div_1"></div>
<div class="div_1"></div>
<div class="div_1"></div>
</div>
function chgclass(o) {
var u = document.getElementById('u');
var c = u.childNodes;
for (var i = 0; i < c.length; i++) {
if (c[i].tagName && c[i].tagName.toLowerCase() == 'div') {
if (c[i] == o) {
c[i].className = 'div_2';
} else {
c[i].className = 'div_1';
}
}
}
}
转载于:https://blog.51cto.com/825272560/1891150