我什至不确定这是否可行,但让我们尝试一下。
我为每个图像动态生成了这个 HTML:
<a href="image.jpg" class="thickbox">
<img src="thumb.jpg" title="This is the title" alt="" />
</a>
不知何故,我需要从thumb.jpg中获取标题属性并将其复制到周围的 anchor ,这将给出以下结果:
<a href="image.jpg" class="thickbox" title="This is the title" alt="">
<img src="thumb.jpg" title="This is the title" alt="" />
</a>
如果这可以通过 jQuery 实现,我会很高兴。
提前致谢。
最佳答案
$('a.thickbox img').each(function(key,$elem){
$(this).parent().attr('title',$(this).attr('title'));
});
如果您有多个图像,则循环使用每个图像。否则,请使用函数中的行并将 $(this)
替换为 $('a.thickbox img')
。
关于jQuery:向元素添加标题属性并从以下元素插入文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12560032/