使用jQuery在单击()时更改图像无效

使用jQuery在单击()时更改图像无效,jquery,Jquery,嗨,朋友们,尝试在点击链接后更改图像,但失败。场景是我建立一个菜单,每个选项卡都有不同的灰色图像,当用户单击该选项卡时,灰色图像将变为白色,当用户单击另一个选项卡时,先前的白色图像返回灰色,新图像将变为白色。您可以查看下面的代码或 HTML <ul data-role="list-divider" class="footerMenu"> <li><a href="#"> <img src="http://s16.posti

嗨,朋友们,尝试在点击链接后更改图像,但失败。场景是我建立一个菜单,每个选项卡都有不同的灰色图像,当用户单击该选项卡时,灰色图像将变为白色,当用户单击另一个选项卡时,先前的白色图像返回灰色,新图像将变为白色。您可以查看下面的代码或

HTML

<ul data-role="list-divider" class="footerMenu">
        <li><a href="#">
        <img src="http://s16.postimg.org/6fnxrzxu9/friends_Icon.png" width="114" height="77" alt=" " />
        <img src="http://s16.postimg.org/7j823yihd/friends_Iconwh.png" width="114" height="77" alt=" " class="active"/><br />
          Friends</a></li>
        <li><a href="#">
        <img src="http://s16.postimg.org/5we94zh1t/cards_Icon.png" width="114" height="77" alt=" " />
        <img src="http://s16.postimg.org/mivte29zl/cards_Iconwh.png" width="114" height="77" alt=" " class="active" /><br />
          Cards</a></li>
        <li><a href="#">
        <img src="http://s16.postimg.org/vt7xhlkpd/egreeting_Icon.png" width="114" height="77" alt=" " />
        <img src="http://s16.postimg.org/lacj667f5/egreeting_Iconwh.png" width="114" height="77" alt=" "  class="active"/><br />
          Egreeting</a></li>
        <li><a href="#">
        <img src="http://s16.postimg.org/hukewma6p/post.png" width="114" height="77" alt=" " />
        <img src="http://s16.postimg.org/nk0ngxgcx/postwh.png" width="114" height="77" alt=" " class="active" /><br />
          Post</a></li>
        <li><a href="#">
        <img src="http://s16.postimg.org/4jwk33jm9/custom_Icon.png" width="114" height="77" alt=" " />
        <img src="http://s16.postimg.org/qkcwjq2a9/custom_Iconwh.png" width="114" height="77" alt=" "  class="active"/><br />
          Custom</a></li>
      </ul>
CSS

body{background:red;}
.footerMenu img.active{display:none;}
请帮帮我,伙计们……提前谢谢:)

试试看

var $as = $('.footerMenu li a'), $imgs = $as.find('img');
$as.on('click', function () {
    var $this = $(this), $cimgs = $this.find('img');
    $as.find('img:first-child').removeClass('active');
    $as.find('img:gt(0)').addClass('active');
    $cimgs.eq(1).removeClass('active');
    $cimgs.eq(0).addClass('active');
})
演示:

var $as = $('.footerMenu li a'), $imgs = $as.find('img');
$as.on('click', function () {
    var $this = $(this), $cimgs = $this.find('img');
    $as.find('img:first-child').removeClass('active');
    $as.find('img:gt(0)').addClass('active');
    $cimgs.eq(1).removeClass('active');
    $cimgs.eq(0).addClass('active');
})