http://feathertest.me.pn/test.php 以上是链接到一个即时通讯工作的网站。JQuery切换多个图像的问题
我有2层主要的功能:
正如我在下面的缩略图单击,一个放大版本出现在更大的箱的上方。我使用的代码是:
$(function(){ $(".thumb").click(function(){ var imagesrc = $(this).children().prop('src'); $('.bigImg').attr('src', imagesrc); }); });
在右侧,我有描绘可用颜色的小方形瓷砖。点击每种颜色时,左侧的扫帚图像将变为显示所选颜色。我使用的代码是:
<script type="text/javascript"> $(function() { $('#showdiv1').click(function() { $('div[id^=div]').hide(); $('#div1').show(); }); $('#showdiv2').click(function() { $('div[id^=div]').hide(); $('#div2').show(); }); $('#showdiv3').click(function() { $('div[id^=div]').hide(); $('#div3').show(); }); $('#showdiv4').click(function() { $('div[id^=div]').hide(); $('#div4').show(); }); })
我的问题: 后我点击缩略图之一(放大图像的版本已成功显示在大框上方)然后当我点击其中一个颜色瓷砖时,扫帚图像只是成功地改变了缩略图,然而,大框中的图像是上一个颜色最后点击的图像。我希望该图像也可以更改为所选颜色。
我的HTML代码片段(我只显示两种颜色的代码):
<div id="feather-prods" class="row">
<div id="div1">
<div id="prod-stop" class="col-md-5 col-sm-6 col-xs-8 col-xs-push-2 col-sm-push-1 col-md-push-1">
<div class="prod-img"><img id="tab1show" class="tab-content bigImg" src="images/broom/monara-pp-1.jpg" alt="feather, Purple monara broom"></div>
<div class="thumbnailImg">
<div id="tab1show" class="tab-content thumb"><img src="images/broom/monara-pp-1.jpg" alt="feather, Purple monara broom" border="0" width="100%" class="thumbImg" /></div>
<div id="tab1show" class="tab-content thumb"><img src="images/broom/monara-pp-2.jpg" alt="feather, Purple monara broom" border="0" width="100%" class="thumbImg" /></div>
<div id="tab1show" class="tab-content thumb"><img src="images/broom/monara-pp-3.jpg" alt="feather, Purple monara broom" border="0" width="100%" class="thumbImg" /></div>
<div id="tab1show" class="tab-content thumb"><img src="images/broom/monara-pp-4.jpg" alt="feather, Purple monara broom" border="0" width="100%" class="thumbImg" /></div>
</div>
</div>
</div>
<div id="div2" style="display:none;" >
<div id="prod-stop" class="col-md-5 col-sm-6 col-xs-8 col-xs-push-2 col-sm-push-1 col-md-push-1">
<div class="prod-img"><img id="tab2show" class="tab-content bigImg" src="images/broom/monara-b-1.jpg" alt="feather, black monara broom"></div>
<div class="thumbnailImg">
<div id="tab2show" class="tab-content thumb"><img src="images/broom/monara-b-1.jpg" alt="feather, black monara broom" border="0" width="100%" class="thumbImg" /></div>
<div id="tab2show" class="tab-content thumb"><img src="images/broom/monara-b-2.jpg" alt="feather, black monara broom" border="0" width="100%" class="thumbImg" /></div>
<div id="tab2show" class="tab-content thumb"><img src="images/broom/monara-b-3.jpg" alt="feather, black monara broom" border="0" width="100%" class="thumbImg" /></div>
<div id="tab2show" class="tab-content thumb"><img src="images/broom/monara-b-4.jpg" alt="feather, black monara broom" border="0" width="100%" class="thumbImg" /></div>
</div>
</div><!-- prod images end -->
</div>
</div>
请帮助。
在此先感谢
我会为每个缩略图添加一个属性,使您可以跟踪某种选定的索引。与位置属性一样,即“”,当您点击它们时,请跟踪该位置当前选定的项目。然后,当您单击不同的颜色时,请检查您正在使用的索引,然后选择其他颜色的相应图像。 –
@JoshuaTerrill问题是我不是很好用JQuery和Javascript。所以我不确定如何去做。 –
下面是我的意思的例子:https://jsfiddle.net/v81dk4dp/1/它是跟踪索引和颜色的东西。您可以单击每个图像,并单击紫色或黄色文本,并在每次点击时切换到相应的图像。比Ray C的例子更复杂,并且有点不好。他还提出了关于身份证的好处。 ID的意思是独一无二的。类不一定是。 –