慕哥6287543
function setStyle(e, a) { var i; for (i in a) { e.style[i] = a[i] }}function changeIcon(index) { var home = document.getElementsByClassName('iconhome_act')[0], server = document.getElementsByClassName('iconservice')[0], user = document.getElementsByClassName('iconuser')[0]; switch (index) { case 0: setStyle(home, { backgroundImage : "url('index/myImg/t_icon_home_active.png')" }) setStyle(user, { backgroundImage : "url('index/myImg/t_icon_user.png')" }); setStyle(server, { backgroundImage : "url('index/myImg/t_icon_service.png')" }); break; case 1: setStyle(home, { backgroundImage : "url('index/myImg/t_icon_home.png')" }) setStyle(user, { backgroundImage : "url('index/myImg/t_icon_user.png')" }); setStyle(server, { backgroundImage : "url('index/myImg/t_icon_service_active.png')" }); break; case 2: setStyle(home, { backgroundImage : "url('index/myImg/t_icon_home.png')" }) setStyle(user, { backgroundImage : "url('index/myImg/t_icon_user_active.png')" }); setStyle(server, { backgroundImage : "url('index/myImg/t_icon_service.png')" }); break; }}我这里的index是外层函数传递的索引值