我正在尝试使用 jQuery 替换给定源的 img 源。例如,当图像 src 为 smith.gif 时,替换为 johnson.gif。如果 williams.gif 替换为 brown.gif 等。
编辑:图像从 XML 检索到随机顺序,每个 .
这是我尝试过的:
if ( $("img").attr('src', 'http://example.com/smith.gif') ) {
$(this).attr('src', 'http://example.com/johnson.gif');
}
if ( $("img").attr('src', 'http://example.com/williams.gif') ) {
$(this).attr('src', 'http://example.com/brown.gif');
}
请注意,我的 HTML 有很多图像。例如
<img src="http://example.com/smith.gif">
<img src="http://example.com/williams.gif">
<img src="http://example.com/chris.gif">
等等。
那么,如何替换图像:IF img src="http://example.com/smith.gif" 然后显示“http://example.com/williams.gif”。等等...
非常感谢