我在基于CMS的网站中有这样的自动生成的代码

<td class="photogalleryItem">
<a onclick="myLightbox.start(this);return false;" rel="lightbox[33136]" href="image1.jpg" title="Test">
<img border="0" src="image1.jpg" alt="Test">
</a>
</td>

我想复制该href标题或图像alt value并按如下所示插入
<td class="photogalleryItem">
   <!--Like This <h3 style="text-align:center;">Test</h3>-->
    <a onclick="myLightbox.start(this);return false;" rel="lightbox[33136]" href="image1.jpg" title="Test">
    <img border="0" src="image1.jpg" alt="Test">
</a>
</td>

在使用javascript或jQuery时,我该怎么做。

此代码在“图库”页面中。所以这对于每个图像都重复

最佳答案

如果您有一个带有td类的photogalleryItem,则可以使用:

$('.photogalleryItem').append('<h3 style="text-align:center;">'+ $('.photogalleryItem').find('img').attr('alt')+'</h3>');

如果您的类td有多个photogalleryItem:
 $('.photogalleryItem').each(function(){
      $(this).append('<h3 style="text-align:center;">'+ $(this).find('img').attr('alt')+'</h3>');
 })

09-18 13:13