[英]caption takes value from image alt attribute
我在此页面中,jQuery代码正在提取alt值并将其放入缩略图下的标题div中。 但是此代码仅适用于第一个。 现在,我希望这些标题显示在每张图片下。 PS。 图片数量会有所不同,可能是10张或20张。
页面网址在这里:
http://sydneyplants02.sajuk.com/Untitled-1.html
非常感谢
请享用 ..!!
$(document).ready(function () {
$('.photogalleryItem').append(function () {
return '<div class="caption">' + $(this).find('img').attr('alt') + '</div>';
});
});
尝试:
$(document).ready(function(){
$("td.photogalleryItem").each(function(){
$(this).find(".caption").text($(this).find("img").attr("alt"));
});
});
这是我的解决方案
$(function(){
$('td.photogalleryItem').each(function(e) {
var $caption = $('<div class="caption">');
$caption.text($('img', $(this)).attr('alt'))
$(this).append($caption);
}
});
这将遍历每个td.photogalleryItem
并添加带有正确alt
文本的标题。 您最初的代码是一个开始,但是问题在于它仅获得第一个td.photogalleryItem
的alt
文本。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.