上点击几图像间切换的Jquery [英] Jquery switching between several images on click

查看:141
本文介绍了上点击几图像间切换的Jquery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用jQuery三幅图像之间进行切换,一旦你点击图像。在点击第三图像上,它切换回第一画面。

I'm trying to use jquery to switch between three images once you click on the image. Upon clicking on the third image, it switches it back to the first picture.

有一个适应两个以上的画面之间切换以下内容,它让更多的比它切换一次的方式?

Is there a way to adapt the following to switch between more than two pictures, and for it to allow more than it switching once?

的jQuery

$(document).ready(function() {
    $("#clickMe").click(function() {
        $("#myimage").attr({src : "picture2.png"});
    });
});

HTML

<div id="clickMe"><img id="myimage" src="picture1.png" /></div>

感谢。

推荐答案

这应该这样做:

$(document).ready(function() { 
    $("#clickMe").click(function() {

        var src = $('#myimage').attr('src');

        //if the current image is picture1.png, change it to picture2.png
        if(src == 'picture1.png') {
            $("#myimage").attr("src","picture2.png");

        //if the current image is picture2.png, change it to picture3.png 
        } else if(src == "picture2.png") {
            $("#myimage").attr("src","picture2.png"); 

        //if the current image is anything else, change it back to picture1.png
        } else {
            $("#myimage").attr("src","picture2.png");
        }
    }); 
});

这篇关于上点击几图像间切换的Jquery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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