我有一些类似下面的代码,它在特定条件下更改文本的字体。 newEntryRow.find("p").find("span").css('color','red');
现在我正在尝试做同样的事情,但要更改图像的来源。我尝试了类似
newEntryRow.find("img").css('src', "foo.png"
);`
我怎样才能做到这一点?
我有一些类似下面的代码,它在特定条件下更改文本的字体。 newEntryRow.find("p").find("span").css('color','red');
现在我正在尝试做同样的事情,但要更改图像的来源。我尝试了类似
newEntryRow.find("img").css('src', "foo.png"
);`
我怎样才能做到这一点?
用于.attr
更改元素的属性,
newEntryRow.find("img").attr('src', "foo.png")
利用
newEntryRow.find("img").attr('src', "foo.png");
您也可以使用 css 设置图像但作为背景
newEntryRow.find("img").css('background-image', "url('path/to/pic')")
不要忘记设置元素的宽度、高度和不重复。
newEntryRow.find('img').attr('src', 'foo.png');
而不是 ".css('src', "foo.png");"
使用 ".attr('src', "foo.png");"
尝试:
newEntryRow.find("img").attr("src","foo.png");
它不是 CSS 属性,而是标签本身的属性:
newEntryRow.find("img").attr('src', "foo.png");
使用 jQueryattr()
方法在 dom 元素上设置任何属性。
newEntryRow.find('img').attr('src', 'foo.png');
newEntryRow.find("img").attr('src', "foo.png");