我试图根据单击的缩略图来更改主图像。
我希望主图像从单击的缩略图的 a 标签中获取新的 src。
我见过其他使用 attr、src 的方法,但在每种情况下,它们都手动指定新的“src”,我如何获取代码以从单击的缩略图的 a 标签中获取 src?
如果有人能告诉我,我将非常感激,谢谢。
编辑:
尝试更改主照片的标题,从单击的缩略图中获取新标题/我的简化代码看起来像这样,
<img src="{hotel_main_photo}" id="main_photo" class="view_page_photo frame" width="420" height="320" alt="{title}" />
<p>{main_caption}</p>
<div id="thumbnails">
<img src="{thumb}" width ="" height="" alt="" />
<p>{thumb_caption}</p>
{/hotel_other_photos}
</div>
我基本上试图更改“main_caption”以显示单击的缩略图的thumb_caption。我可以将thumb_caption存储为标题或alt,如果这有帮助的话?
再次感谢再次
编辑(!)
我认为使用詹姆斯的建议,我已经通过以下
$("#main_caption").text($(this).attr("alt"));弄清楚了它
I'm trying to get the main image to change depending on the thumbnail image clicked.
I would want the main image to take its new src from the a tag of the thumbnail that was clicked.
I've seen other methods using attr, src but in each case they specify manually the new "src", how could i get the code to take the src from the a tag of the thumbnail clicked?
Would really appreciate if anyone could show me, thanks.
EDIT:
Trying to change the caption of the main photo, getting the new caption from the thumbnail clicked/ My simplified code looks like this
<img src="{hotel_main_photo}" id="main_photo" class="view_page_photo frame" width="420" height="320" alt="{title}" />
<p>{main_caption}</p>
<div id="thumbnails">
<img src="{thumb}" width ="" height="" alt="" />
<p>{thumb_caption}</p>
{/hotel_other_photos}
</div>
I'm basically trying to change the 'main_caption' to display the thumb_caption of the thumbnail clicked. I could store the thumb_caption as the title or alt if that would help?
Thanks again
EDITED AGAIN(!)
I think using James' suggestion, I've sort of figured it out with the following
$("#main_caption").text($(this).attr("alt"));
发布评论
评论(1)
像这样的事情应该可以解决问题:
它只是获取单击的
.thumbnail
元素的src
并将其用作src
值>#mainImage。Something like this should do the trick:
It simply gets the
src
of the clicked.thumbnail
element and uses it as thesrc
value of#mainImage
.