jQuery找到一个img src [英] JQuery find an img src

查看:93
本文介绍了jQuery找到一个img src的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用JQuery,我希望能够获得img src链接.

With JQuery I want to be able to get the img src link.

   <tbody>
            <tr>
                <td headers="header_0 header_1">&#160;<img
                    src="https://this-link-here.com" width="26"
                    height="24" alt="" border="0" /></td>

我尝试过

   var data = $(data).find("[headers='header_0 header_1']");

但是这没有得到链接.同样,我尝试添加.text().html(),但还是没有运气.

but this is not getting the link. Similarly I have tried adding .text(), and .html() but still no luck.

任何人都可以帮忙吗?无法更改HTML.

Can anyone help? The HTML cannot be changed.

推荐答案

您可以使用 .attr() 函数:

var data = $(data).find("[headers='header_0 header_1']").find('img').attr("src");

如果只有一个带有这些标头,则使用香草JS .src函数:

Or the vanilla JS .src function, if there is only one with those headers:

var data = $(data).find("[headers='header_0 header_1']").find('img').get(0).src;

香草JS方式更快,这只是我扔进去的原因.

The vanilla JS way is faster, only reason I threw it in.

这篇关于jQuery找到一个img src的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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