使用'alt'值动态设置'title' [英] Use 'alt' value to dynamically set 'title'

查看:142
本文介绍了使用'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或任何其他方法来获取<来自我的图片的code> alt 属性,并动态覆盖我的 a title 属性$ c>标签。

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"));
   });
});

这篇关于使用'alt'值动态设置'title'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆