jQuery更改< img src =“""的值.按ID [英] JQuery change the value of an <img src="" by ID
本文介绍了jQuery更改< img src =“""的值.按ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要一些简单的JQuery代码,以便可以更改特定img的src值.
I need some simple JQuery code so I can change the src value of a specific img.
当前:
<img id="myImage" src="image1.gif" />
,我需要将其更改为:
<img id="myImage" src="image2.gif" />
使用JQuery.
推荐答案
使用:$(function(){ ... });
您可以使用:
$('#id').attr('src', 'newImage.jpg');
立即更改图像源.
或者,您可以使用jQuery动画来更改图像.
Alternatively, you can use jQuery animations to change an image.
JS
$("#id1").fadeOut();
$("#id2").delay(200).fadeIn();
HTML
<div>
<img id='id1' src='one.jpg'>
<img id='id2' src='two.jpg'>
</div>
(不要忘记更改#id2
的CSS并将display: none
设置为初始状态).
(Don't forget to change the CSS of #id2
and put display: none
as initial state).
这篇关于jQuery更改< img src =“""的值.按ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文