使用 'alt'动态设置 'title' 的值 [英] Use 'alt' value to dynamically set 'title'
本文介绍了使用 'alt'动态设置 'title' 的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要一些帮助,在我们开始之前,我知道这可能不是最佳实践,但我正在对现有站点进行一些维护,需要完成以下操作以进行修复.
I need some help, and before we get going, I know it is probably not best practice, but I am doing some maintenance to an existing site and need to accomplish the following for a fix.
<a rel="lightbox" href="site.com" title="a generated title">
<img src="site.com/img" class="post-image" alt="a long description"/>
</a>
好的,所以我想弄清楚如何使用 jQuery 或任何其他方法从我的图像中获取 alt
属性,并动态覆盖的 title
属性我的 a
标签.
Okay, so I am trying to figure out how to use jQuery or any other method to take the alt
attribute from my image, and dynamically overwrite the title
attribute of my a
tag.
任何帮助都会很棒,此时我有点迷茫.
Any help would be awesome, I am kinda lost at this juncture.
推荐答案
$(function(){
$("a").each(function(){
$(this).attr("title", $(this).find("img").attr("alt"));
});
});
这篇关于使用 &#39;alt&#39;动态设置 &#39;title&#39; 的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文