2011-04-25 27 views
1

我有一个头3标记内的图像,我有一个jQuery的功能,展开和折叠表。当功能完成时,我需要更改展开/折叠图标,我可以这样做。我的问题是,即使它没有ID,我是否可以更改h3标签内的图像?有没有办法在jQuery中没有id的img标签上设置背景图片?

因此,像:

$(this.img).css("backgroundImage", "url(images/expand.png)"); 

回答

1
$('h3').find('img').attr('src', 'url(images/expand.png)') 

或者因为你有切换中的引用:

$(this).find('img').attr('src', 'url(images/expand.png)') 
0

你为什么要设置CSS,而不是改变图像的src?试试 $("img", this).attr("src", "images/expand.png");

+0

对不起,我想通了这一点,我张贴此之后,但我仍想知道的无标识的一部分。 – Dennis 2011-04-25 20:13:42

0

是的,这是可能的。你有一个错字。 backgroundImage应该background-image这样的:

$(this.img).css("background-image", "url(images/expand.png)"); 
0

当然..

$('h3 img').css(/* --- */); 

只要不使用.img,因为这是所谓的 “IMG” CSS类。

0

当然,

$(this).animate({'height':'toggle'},function(){$(this).find('img').attr('src','pathtoimage.png');}) 
相关问题