2010-05-10 49 views
0
<IMG height="160" alt="Web Content Image" src="../image/journal/article?img_id=16505&t=1273484793531" width="240" pngSet /> 

我对图像的代码,我想基于属性“pngSet”如何根据属性选择IMG标签?

我想这一点,但不是工作选择图像。

$("img[pngSet='']").css('border' ,'1px solid red'); 

回答

4

你可以这样说:

$("img[pngSet]").css('border' ,'1px solid red'); 

has attribute selector只是[attributeName] :)

+0

我很好奇,为什么它没有虽然匹配。 http://jsbin.com/adida4起作用。 – wombleton 2010-05-10 10:32:24

+0

@wombleton - 虽然我不能保证跨浏览器,但我不记得哪些是失败的,但有一些,或者至少曾经是。 – 2010-05-10 11:18:28

0

它通常是一个坏主意组成attri butes。浏览器不必支持它。最好的办法是使用一个类来代替:

<IMG height="160" alt="Web Content Image" src="../image/journal/article?img_id=16505&t=1273484793531" width="240" class="pngSet" /> 
$("img.pngSet").css('border' ,'1px solid red');