jQuery:如何通过其src查找图像 [英] jQuery: How to find an image by its src

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

问题描述

我需要按名称和src查找img.我一直在尝试以下方法无济于事.

I need to find an img by name and src. I have been trying the following to no avail.

var s = $("img[src='/images/greendot.gif'][name='BS']");

html:

<img alt="This item is active." name="BS" src="/images/greendot.gif"/>

vs

<img alt="This item is not active." name="BS" src="/images/spacer.gif"/>

推荐答案

没有看到html,我会说要检查您的路径.

without seeing the html I would say check your path.

$("img[src$='greendot.gif'][name='BS']")

使用以下HTML:

<img src="http://assets0.twitter.com/images/twitter_logo_header.png" name="logo" />

此jquery有效:

var x = $("img[src$='twitter_logo_header.png'][name='logo']");
alert(x.attr("src"));

这篇关于jQuery:如何通过其src查找图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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