1

我有一些类似下面的代码,它在特定条件下更改文本的字体。 newEntryRow.find("p").find("span").css('color','red');

现在我正在尝试做同样的事情,但要更改图像的来源。我尝试了类似 newEntryRow.find("img").css('src', "foo.png");`

我怎样才能做到这一点?

4

8 回答 8

4

用于.attr更改元素的属性,

newEntryRow.find("img").attr('src', "foo.png")
于 2012-04-24T18:06:29.097 回答
1

利用

 newEntryRow.find("img").attr('src', "foo.png");

您也可以使用 css 设置图像但作为背景

 newEntryRow.find("img").css('background-image', "url('path/to/pic')")

不要忘记设置元素的宽度、高度和不重复。

于 2012-04-24T18:06:31.227 回答
0
newEntryRow.find('img').attr('src', 'foo.png');

http://api.jquery.com/attr/

于 2012-04-24T18:06:34.593 回答
0

而不是 ".css('src', "foo.png");"

使用 ".attr('src', "foo.png");"

于 2012-04-24T18:20:06.237 回答
0

尝试:

 newEntryRow.find("img").attr("src","foo.png");
于 2012-04-24T18:06:43.390 回答
0

它不是 CSS 属性,而是标签本身的属性:

newEntryRow.find("img").attr('src', "foo.png");
于 2012-04-24T18:07:00.797 回答
0

使用 jQueryattr()方法在 dom 元素上设置任何属性。

newEntryRow.find('img').attr('src', 'foo.png');

参考:http ://api.jquery.com/attr/

于 2012-04-24T18:07:12.170 回答
0
newEntryRow.find("img").attr('src', "foo.png");
于 2012-04-24T18:07:26.200 回答