【发布时间】:2011-09-08 22:32:55
【问题描述】:
我有一个产品页面,其中包含图像缩略图以及用于更改缩略图的封面和封底链接。问题是,当您单击这些链接以更改缩略图时,其余产品缩略图的所有图像也会更改。
如何将点击事件绑定到该产品,以便仅更改缩略图?
This is my HTML (this list is repeated bellow for other products with different images):
<div class="product-main-image">
// Here I have the thumb image
<a href="Images/cards/us-sip-connect-5-front-hi-res.jpg" class="product-main-image-hover">
<img src="Images/cards/us-sip-connect-5-front.jpg" class="product-image" />
</a>
// When I click front or back links it's changing all the thumbs for other product as well.
<ul class="thumbs">
<li><a href="Images/cards/front.jpg" rel="Images/cards/front-hi-res.jpg">Front</a></li>
<li><a href="Images/cards/back.jpg" rel="Images/cards/back-hi-res.jpg">Back</a></li>
</ul>
</div>
This is the jQuery:
$('.thumbs a').live('click', function(){
// Get the thumb image tag attributes
var image_thumb = $(this).attr("href");
var image_hi_res = $(this).attr("rel");
// switch the image by removing the node and re-writing in the neccessary HTML
$('.product-main-image-hover').remove();
$('.product-main-image').append('<a href="' + image_hi_res + '" class="product-main-image-hover"><img src="' + image_thumb + '" class="product-image" /></a>');
return false;
});
希望有人能引导我朝着正确的方向前进。谢谢。
【问题讨论】: