如何改变img url? (带/类)

时间:2013-11-18 13:37:53

标签: javascript jquery css image

添加/删除有效的动画输入/输出类(http://hostelgoodmo.com/test.gif),以及如何更改img网址?

新幻灯片=>添加gif =>启动gif动画=> (删除旧的GIF)下一张幻灯片=>添加gif ....

幻灯片1:     

<li class="slide-one animate-in">
<img src="active.gif">
</li>

<li class="slide-two">
<img src="none.png">
</li>

<li class="slide-four">
<img src="none.png">
</li>

</ul>

幻灯片2:     

<li class="slide-one animate-out">
<img src="none.png">
</li>

<li class="slide-two animate-in">
<img src="active.gif">
</li>

<li class="slide-four">
<img src="none.png">
</li>

</ul>

幻灯片3:

<ul class="animation-canvas">

<li class="slide-one animate-out">
<img src="none.png">
</li>

<li class="slide-two animate-in">
<img src="none.png">
</li>

<li class="slide-four">
<img src="active.gif">
</li>

</ul>

2 个答案:

答案 0 :(得分:3)

非常简单:

$('selector_to_img_tag').attr('src','what you want');

答案 1 :(得分:1)

使用jQuery更改图像的src属性。

HTML:

<img src="http://www.hdwallpapersdj.com/wp-content/uploads/2013/09/cartoon-1.jpg" width="100px" height="100px" />

<input type="button" value="Change Image" />

jQuery:

$("input").click(function(){
    var newImageUrl = "http://images2.fanpop.com/image/photos/14000000/Disney-Cartoon-wallpaper-classic-disney-14019904-1024-768.jpg";
    $("img").attr("src", newImageUrl);
});

Demo