Menu picture switching problem?

there is such a requirement, as shown in the figure are four menu buttons. The four menu icons here are not vector icons similar to Font Awesome, but pictures in png format, namely f.png, u.png, s.png, and p.png.

demand: clicking on the corresponding picture will show the transparent picture of its corresponding f_a.png. When clicking on other pictures (the clicked picture link is transformed into some _ a.png, and so on), the original picture will be restored to f.png. So how do you do it using js here? (ignore vector icons)


one class per icon

.home {
    background: url(f.png)
}

add the active class after clicking, and remove the active class of other buttons

.home.active {
    background-img: url(f.png)
}

js


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;

    }

}

my index is the index value passed by the outer function

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b318f8-40de6.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b318f8-40de6.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?