如何在2张图像之间切换 [英] How can I toggle between 2 images

查看:92
本文介绍了如何在2张图像之间切换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用此代码在播放按钮和暂停按钮之间切换,但似乎不起作用.当点击

Im trying to use this code to toggle between a play and pause button but it doesn't seem to be working. How can I get it toggle between the 2 images when the are clicked

http://jsfiddle.net/aFzG9/1/

$("#infoToggler").click(function()
{
    if($(this).html() == "<img src="http://tympanus.net/PausePlay/images/play.png" width="60px" height="60px"/>")
    {
        $(this).html("<img src="http://maraa.in/wp-content/uploads/2011/09/pause-in-times-of-conflict.png width="60px" height="60px"/>");
    }
    else
    {
        $(this).html("<img src="http://tympanus.net/PausePlay/images/play.png" width="60px" height="60px"/>");
    }
});

谢谢

推荐答案

另一种可能更简单的处理方式:

A different maybe easier way to handle it:

http://jsfiddle.net/M9QBb/1/

$("#infoToggler").click(function() {
    $(this).find('img').toggle();
});​

<div id="infoToggler">
  <img src="image1.png" width="60px" height="60px"/>
  <img src="image2.png" width="60px" height="60px" style="display:none"/>
</div>

这篇关于如何在2张图像之间切换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆