【发布时间】:2012-01-01 21:43:53
【问题描述】:
JSFIDDLE HERE
在按下.miniimg/2/3 时,它应该替换我使用 jquery 附加到 div .imgcontainer 的 img 分类 .presentimg 的 src,我已经通过 jQuery (BELOW HTML) 和我认为它不起作用的唯一原因是因为我在函数中使用了函数并且我不知道替代方法
<div class="imgcontainer">
<div class="minicontainer">
<img src="http://lh3.googleusercontent.com/_Zuzii37VUO4/Ta0nUeMwXoI/AAAAAAAAFoc/7f0Um7OTgNg/s000/Antartic-by-Peter-Rejcek.jpg" title="icy mountains" class="miniimg"/>
<img src="http://lh3.googleusercontent.com/_Zuzii37VUO4/Ta0nUFUhg6I/AAAAAAAAFoY/GToUxRYcteY/s000/Antartic-by-Kelly-Speelman.jpg" title="icy planes and hills" class="miniimg2"/>
<img src="http://lh4.googleusercontent.com/_Zuzii37VUO4/Ta0nTs8AbPI/AAAAAAAAFoU/zCvNKv4kfe4/s000/BeachWaves-By-RePublicDomain.jpg" title="sun rise with clouds" class="miniimg3"/>
</div>
</div>
jquery,我在 jquery 中使用(索引)作为外部 .each 函数,正如我在论坛上看到的那样,但我不知道这是否真的有效
$(".imgcontainer").each(function(){
var imgsrc = $(".minicontainer img:first-child").attr("src");
$(this).append('<img src="'+imgsrc+'" class="presentimg"/>');
});
$(".miniimg").each(function(index){
var $this = $(this);
$(this).click(function(){
var miniimgrc = $this.attr("src");
$(".presentimg").atrr('src', miniimgrc);
});
});
$(".miniimg2").each(function(index){
var $this = $(this);
$(this).click(function(){
var miniimgrc2 = $this.attr("src");
$(".presentimg").atrr('src', miniimgrc2);
});
});
$(".miniimg3").each(function(index){
var $this = $(this);
$(this).click(function(){
var miniimgrc3 = $this.attr("src");
$(".presentimg").atrr('src', miniimgrc3);
});
});
【问题讨论】:
标签: javascript jquery image each src