简体   繁体   English

使用JavaScript单击时如何更改图像?

[英]How to change an image when clicked using JavaScript?

I've created a sliding image viewer here . 我在这里创建了一个滑动图像查看器。 As you can see, there's 4 small clickable images to change/slide the image. 如您所见,有4个可点击的小图像来更改/滑动图像。 I want the small image to change to this image alt text http://beta.d-load.org/images/etc/imagev-on.png when it's clicked, or when the appropriate main image is showing. 我希望在单击小图像或显示适当的主图像时,将小图像更改为该图像的替代文本http://beta.d-load.org/images/etc/imagev-on.png That way the users can tell which main image is being shown. 这样,用户可以知道正在显示哪个主图像。 Can anyone maybe look at the source and explain how to do this? 谁能看看源代码并解释如何做到这一点? Thanks! 谢谢!

try the following code !! 试试下面的代码!

var src = [];
    src['normal'] = "http://beta.d-load.org/images/etc/imagev-norm.png";
    src['active'] = "http://beta.d-load.org/images/etc/imagev-over.png";
$(document).ready(function() {
    $('a',$('.paging')).click(function() {
       $('a',$('.paging')).find('img').attr('src',src['normal']);  
       $(this).find('img').attr('src',src['active'])   ;
    });
});

Here you go, Demo : http://jsfiddle.net/qTB9g/ 演示 ,您在这里: http : //jsfiddle.net/qTB9g/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM