我在标题3标记内有一个图像,我有一个jquery函数,可以扩展和折叠表。我需要在功能完成后更改展开/折叠图标,我可以这样做。我的问题是,我是否可以更改h3标签内的图像,即使它没有id?
类似于:
$(this.img).css("backgroundImage", "url(images/expand.png)");
答案 0 :(得分:1)
$('h3').find('img').attr('src', 'url(images/expand.png)')
或者因为你在切换中有一个参考:
$(this).find('img').attr('src', 'url(images/expand.png)')
答案 1 :(得分:0)
为什么要设置CSS而不是更改图像的src?尝试
$("img", this).attr("src", "images/expand.png");
答案 2 :(得分:0)
是的,这是可能的。你有一个错字。 backgroundImage
应为background-image
,如下所示:
$(this.img).css("background-image", "url(images/expand.png)");
答案 3 :(得分:0)
不确定..
$('h3 img').css(/* --- */);
请不要使用.img
,因为这是针对名为“img”的css类。
答案 4 :(得分:0)
当然,
$(this).animate({'height':'toggle'},function(){$(this).find('img').attr('src','pathtoimage.png');})